Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Anonymous versus Declared inner classes

 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All, What is the advantage of using an anonymous inner class over a declared inner class?
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know of no technical advantages of one over the other as far as speed, resources used, etc, but for very small classes that are not reused, anonymous inner classes may make the code simpler and easier to read (for some) since the functionality of the class is held right where you're wanting to use it. Overuse and inappropriate use will have the opposite effect.
 
Marshal
Posts: 70353
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is quicker to write. If you are going to use objects of that class in several places, however, or similar objects, you are probably better of with a declared and named class (inner or top-level).
 
Dan Grindstaff
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!
 
Campbell Ritchie
Marshal
Posts: 70353
283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Catch Ernie! Catch the egg! And catch this tiny ad too:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic