• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using comparator as an Innerclass  RSS feed

 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
IS there any benefit of using an class that implements comparator as an inner class compared to using it separately & importing it .
Regards.
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the comparator is associated with the relevant class only (or even strongly associated with it..), it makes organisational sense to include it as a nested class.

Look at the field CASE_INSENSITIVE_ORDER in the String class, which is a Comparator. This is implemented as a static nested class. (Check the Open JDK String class source)
[ November 05, 2008: Message edited by: Gamini Sirisena ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!