Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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: 23912
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: 22573
122
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
$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: 22573
122
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

Naman Patidar wrote:Inline method overriding


That's called "creating an anonymous inner class".
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic