No enclosing instance of type 클래스이름 is accessible. Must qualify the allocation with an enclosing instance of type 클래스이름

장시영·2022년 5월 13일

해석

닫혀있는 Object 객체에 접근할 수 없다. 반드시 닫혀있는 Object 객체에 allocation 자격을 주어라.

원인

static인 main 메서드는 컴파일 과정에서 가장 먼저 메모리에 올라간다. 그래서 Value 클래스를 포함한 Object 클래스가 아직 메모리에 올라가지 않은 상태에서 Value 클래스를 찾으려고 하니 오류가 발생함.

해결

  1. Value 클래스에 static 을 주기

  2. Value 클래스를 Object 클래스 밖으로 빼기

profile
코딩주니어

0개의 댓글