• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Collections creating inner classes

 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Collections for sorting. The Collections creates innerclasses say Class$1.

I havent noticed this behaviour previously. Is this expected?

Thanks in Advance
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

There are lots of inner classes related to collections... but you shouldn't be getting any extra ones just because you compiled code that uses them. If you are getting new inner classes in your code, it should be noticeable in your code. It shouldn't be too hard to check.

Henry
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
$1 and beyond indicate anonymous inner classes (look it up if you don't know what that means). It essentially uses an incremental number for each anonymous inner class encountered in the source code.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Inline method overriding might be used somewhere in the code.
following code demonstrate it :

public class InnerClassTest implements Comparable {
@Override
public int compareTo(Object o) {
return 0;
}

public static void main(String[] args) {
InnerClassTest i1 = new InnerClassTest(){
@Override
public int compareTo(Object o) {
return 1;
}
};
InnerClassTest i2 = new InnerClassTest();
System.out.println(i1.compareTo(i2));
System.out.println(i2.compareTo(i1));
}
}
 
Rob Spoor
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Naman Patidar wrote:Inline method overriding


That's called "creating an anonymous inner class".
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic