문제

It might sound like a dumb question, but all anonymous classes must be defined and instantiated within an existing class; therefore, they must be inner classes at the same time.

도움이 되었습니까?

해결책 2

This is quite true. Your anonymus class could not be implemented outside of other classes, as a seperate class, because as it is anonymus you would not be even able to refer to it in any way.

Additional information: From JLS: An anonymous class is always an inner class (§8.1.3); it is never static (§8.1.1, §8.5.1).

다른 팁

Anonymous classes are types of inner classes. See http://docs.oracle.com/javase/tutorial/java/javaOO/innerclasses.html

Quoting from there:

"You can also declare an inner class within the body of a method without naming the class. These classes are known as anonymous classes."

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top