syntax - Is it possible to make anonymous inner classes in Java static? - Stack Overflow
No, you can't, and no, the compiler can't figure it out. This is why FindBugs always suggests changing anonymous inner classes to named static
nested classes if they don't use their implicit this
reference.
Edit: Tom Hawtin - tackline says that if the anonymous class is created in a static context (e.g. in the main
method), the anonymous class is in fact static
. But the JLS disagrees:
An anonymous class is never
abstract
(§8.1.1.1). An anonymous class is always an inner class (§8.1.3); it is neverstatic
(§8.1.1, §8.5.1). An anonymous class is always implicitlyfinal
(§8.1.1.2).
Read full article from syntax - Is it possible to make anonymous inner classes in Java static? - Stack Overflow
No comments:
Post a Comment