bbaja42
bbaja42

Reputation: 2169

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?

Upvotes: 6

Views: 1274

Answers (2)

Dead Programmer
Dead Programmer

Reputation: 12575

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

    };
}

Upvotes: 1

Pablo Grisafi
Pablo Grisafi

Reputation: 5047

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

Upvotes: 19

Related Questions