• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't understand this formatting  RSS feed

 
Alessandro Camel
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this tutorial
http://www.mkyong.com/java/how-to-read-xml-file-in-java-sax-parser/

but I can't really understand what is going on here:




I was expecting a ; after "new DefaultHandler()".
Why I find methods,and variables declarations ?
What am I missing ?

 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you have there is an anonymous inner class. It's basically a subclass that you don't give a name.
 
Alessandro Camel
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:What you have there is an anonymous inner class. It's basically a subclass that you don't give a name.


Thanks a lot!!!
I know about inner classes, but not about anonymous......

Time to step back, and going to study it !
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alessandro Camel wrote:I found this tutorial
http://www.mkyong.com/java/how-to-read-xml-file-in-java-sax-parser/

but I can't really understand what is going on here:




I was expecting a ; after "new DefaultHandler()".
Why I find methods,and variables declarations ?
What am I missing ?

You are actually missing a ;
And a }
What you have actually got is You have quoted the beginnings of an anonymous class. What you can do is take a class or interface and fill in methods or fields. You usually do it to abstract classes and interfaces, but you can do it to concrete classes too. You can add implement or override any methods. You can add fields. You can't add a constructor, but have to use the constructor from the superclass.
You can find out the details of the methods by looking up that class (or more probably interface) in the documentation: here.

You now have an object of a class which implements/extends DefaultHandler, and any abstract methods have been fully implemented.

If you search here, in "Swing" and in JiG for "anonymous class" you will find lots of other discussions about this question.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!