Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Java code with an inner class generates a third SomeClass$1.class file?

If I have an inner class, like this:

public class Test
{
    public class Inner
    {
        // code ...
    }

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

When I compile it, I expect it should generate two files:

Test.class
Test$Inner.class

So why do I sometimes see classfiles like SomeClass$1.class, even though SomeClass does not contain an inner class called "1"?

like image 233
Johan Avatar asked Dec 19 '08 08:12

Johan


People also ask

How many bytecode files are generated for inner class?

Explanation : The java compiler creates two class files in case of inner class.

How many .class files are created in Java?

class" files are created in the corresponding folder as there are four classes are defined in the "ClassTest. java" file. Those are A. class, B.

How many .class files are generated?

For Compiling: After compilation there will be 3 class files in corresponding folder named as: Sample. class.

How many inner classes can you have in your Java files?

There are basically four types of inner classes in java.


1 Answers

The SomeClass$1.class represent anonymous inner class

hava a look at the anonymous inner class section here

like image 111
hhafez Avatar answered Sep 26 '22 00:09

hhafez