내부 클래스의 인스턴스를 만드는 방법을 알고 있습니다. 하지만 우리는 다음과 같은 방법으로 그렇게 할 수없는 이유를 알고 싶어 :왜 우리는 외부 클래스의 main 메소드 안에 내부 클래스의 인스턴스를 규칙적으로 만들 수 없습니까?
class outerclass{
public static void main(String[] args){
innerclass in=new innerclass();
}
class innerclass{
}
}
그때 나는 다음과 같은 오류 얻을이 작업을 수행 할 경우
No enclosing instance of type outerclass is accessible. Must qualify the allocation with an enclosing instance of type outerclass (e.g. x.new A() where x is an instance of outerclass).
왜?
"둘러싼 인스턴스"가 무엇인지 알고 있습니까? 'innerclass'는 암시 적으로'outerclass' 타입의 필드를 가지고 있다는 것을 알고 있습니까? 그 분야의 가치가 당신의 모범에 무엇을 기대합니까? –
흠 ... 특정 오류 메시지가 논의 된 적이 있는지 확인할 수있는 일종의 글로벌 인터넷 검색이 있다면 얼마나 편리할지 상상해보십시오. – shmosel