• Post Reply Bookmark Topic Watch Topic
  • New Topic

Anonymous Inner Class?  RSS feed

 
Sam Samson
Ranch Hand
Posts: 63
IntelliJ IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Is line 30 creating an anonymous inner class, or what purpose have the curly brackets there?


 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Samson wrote:Is line 30 creating an anonymous inner class

Yes; although the word 'inner' is a bit redundant when it comes to anonymous classes.

Winston
 
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
Note that in that example, it's a bit pointless to create an anonymous subclass of Bar. It could just as well have been:
 
Avinash Ga
Ranch Hand
Posts: 78
Eclipse IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
normally anonymous inner classes are created against interfaces / abstract classes. so as Jesper de Jong said, its pointless to create Bar as inner class.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What the empty pair bf braces do, is to delimit a class body which has nothing in. So you are creating an instance of an anonymous subclass of Bar which embodies no changes!It will only compile if the superclass has an accessible no-arguments or default constructor.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!