• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Regarding Anonymous and Static classes

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,

Can you please explain to me, what is the common uses of Anonymous classes and Static classes?
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Comparator is commonly implemented as an anonymous class, because it doesn't really carry any logic and is mostly done in 2 lines of code. Also, check here http://www.gawer.org/books/OReilly_Reference_Library/javaenterprise/jnut/ch03_12.htm

as for static inner classes, you use them when there is no need to have a reference of the enclosing class if you want to use the inner class.
 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any class instance can be anonymous; an object reference without a name. This is
useful in GUI code, for example, where many listener objects are often needed.
Below, "new JButtonListener()" creates an anonymous class that is passed directly
to the button. (It gets a name in the JButton constructor.) I/O operations use a lot
of anonymous classes too.

Sebastian explained static nested classes (the non-static kind are called inner classes).
But if you are asking more generally about static class members (attributes, methods,
static nested classes), they provide singleton behavior for your application.

Jim... ...
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic