Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does dollar followed by an index mean in a class name?

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?

like image 492
bbaja42 Avatar asked Dec 20 '11 12:12

bbaja42


2 Answers

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

like image 84
Pablo Grisafi Avatar answered Nov 15 '22 00:11

Pablo Grisafi


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() {

    };
}
like image 45
Dead Programmer Avatar answered Nov 14 '22 23:11

Dead Programmer