• Post Reply Bookmark Topic Watch Topic
  • New Topic

can anonymous class be static ?  RSS feed

 
Ranji Sura
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.. Please look at this...



8.1.1. Class Modifiers
The modifier static pertains only to member classes (§8.5.1), not to top level or local or anonymous classes.


http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.9.5
An anonymous class is always an inner class (§8.1.3); it is never static (§8.1.1, §8.5.1).


So, if it is anonymous class, it can't be an inner class and it can not be static
But static pertains only to member classes

What do you think .. ?
Is this anonymous class or member class ? It certainly doesn't have a name though..
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you're creating in line 9 is an anonymous class that implements interface A.

The class is not static, but the member variable a that you're storing the instance in, is static. That's not the same as the class being static.
 
Ranji Sura
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, thank you...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!