Created
March 1, 2024 15:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 추상 클래스 정의 | |
abstract class MyAbstractClass { | |
// 추상 메서드 | |
abstract void myAbstractMethod(); | |
} | |
public class Example { | |
public static void main(String[] args) { | |
// 익명 클래스 사용 | |
MyAbstractClass anonymousClassInstance = new MyAbstractClass() { | |
@Override | |
void myAbstractMethod() { | |
System.out.println("Abstract method implemented using anonymous class"); | |
} | |
}; | |
anonymousClassInstance.myAbstractMethod(); | |
// 람다 표현식 사용 - 오류 발생! | |
// 추상 클래스는 람다 표현식으로 대체할 수 없음 | |
// MyAbstractClass lambdaInstance = () -> System.out.println("Abstract method implemented using lambda"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment