6

I'm profiling a java application, and the largest number of the allocated objects have name com.x.y.ClassName$5.

Both the netbeans profiler and the yourkit use the same naming convention. I'm at loss how to google the naming problem.

What is $5 after class name?

EDIT: It seems the $5 is fifth anonymous class declared. I've used javap on generated class to find which is the fifth anonymous class. Reference found in How to match compiled class name to an enum member in Java?

Community
  • 1
  • 1
bbaja42
  • 2,099
  • 18
  • 34

2 Answers2

19

com.x.y.ClassName$5 means "the fifth anonymous inner class in com.x.y.ClassName"

Pablo Grisafi
  • 5,039
  • 1
  • 19
  • 29
  • Wow, quick answer. Is there a way how to tell which inner class is 5th? – bbaja42 Dec 20 '11 at 12:45
  • I'm not aware of any way to do that. So I'm not happy with my own answer. Saying "fifth" without saying the specific order is like saying "a random number". However, if you have a good decompiler like [JD](http://java.decompiler.free.fr/) can show you the code of any inner class – Pablo Grisafi Dec 20 '11 at 12:54
  • 1
    I think that it is the order in which they are declared... Anyway, you can overwrite the toString() to provide some meaningful representation in the debugger. – fortran Dec 20 '11 at 13:25
  • @fortran How will to toString method change Class name? – bbaja42 Dec 20 '11 at 17:39
  • 1
    @bbaja42 it won't change the class name at all, but in most IDEs if you hover the mouse over a live object it will show its toString() representation (that by default is the class name and some hash). – fortran Dec 20 '11 at 17:45
1

Some links to help you. Also look at polygenelubricant's answer

you get com.x.y.ClassName$5. when your class contains a anonyomous inner class

    sample8.class
    sample8$1.class
    sample8$2.class
    sample8$klass.class
    sample8$klass$1.class

Example

   public class sample8 {


        private class klass{
            void vodka() {
                sample8 _s = new sample8() {

                };

            }
        }
        sample8() {
               klass _k = new klass();
              _k.vodka();
           }


    public static void main(String args[])
    {
    }

    sample8 _s = new sample8() {

    };

    sample8 _s1 = new sample8() {

    };
}
Community
  • 1
  • 1
Dead Programmer
  • 12,427
  • 23
  • 80
  • 112