반응형 익명클래스2 익명클래스 -> Lambda(람다식) 변환 예제 Java 8 이상 부터는 익명 내부 클래스를 Lambda 식으로 변환하여 코드를 간결하게 바꿀수 있게 되었다.익명 클래스에 대해서는 아래 참고 포스팅 참고 바란다. 많이 쓰이는Eclipse 에서는 익명클래스에 커서 두고 Ctrl+1 을 눌러서 replace with lambda 를 클릭해서 자동으로 바꿀수도 있고,Intellij 에서는 옵션+엔터를 해서 replace with lambda 를 만날수 있다. 그럼 이 Lambda 식이 뭐고 어떻게 변환이 되는지 간단하게 예제 코드로 알아보자.(이하는 편의상 람다라고 칭함) 우선 chatGPT 에 간단하게 바꾸는 예제 코드를 알려달라고 하면 Runnable 인터페이스를 예시로 들어주었다.아래와 같다. 익명클래스 예제 코드public class Main { .. 2024. 10. 22. 익명 클래스(anonymous class)란? 먼저 oracle 에서 소개하는 익명클래스에 대해서는 아래 링크에서 확인 가능하다. https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html Anonymous Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects) The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology n.. 2023. 2. 25. 이전 1 다음 반응형