• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't understand this formatting

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic