Rogue class file - Outer$1.class

Hey peeps,

Here’s a bit of a wierd one for you; I’d be very grateful if anyone can give me a reason why the following happens, could tell me whether or not it’s a bug, and whether it has been fixed in the latest JDK - I’m running JDK 1.4.1_01:

public class Outer
{
      private class Inner
      {
      }

      Inner i = new Inner() ;
}

When this class is compiled it produces three class files, Outer.class, Outer$Inner.class and Outer$1.class. What is Outer$1? It is generated whenever the class is compiled, but can be deleted without affecting the class’ functionality. When decompiling the three class files together, a single file equivalent to the above is generated - subsequently compiling this file produces the three class files again.

Decompiling just the Outer$1.class file produces the following:

class Outer$1
{
}

Decompiling just the Outer$Inner.class file produces the following:

private class Outer$Inner
{
      private Outer$Inner()
      {
            super();
      }

      Outer$Inner(Outer$1 outer$1)
      {
            this();
      }
}

So what is that second constructor? Why can life continue fine without the class existing? And is this expected behaviour?

Cheers,
Charlie.

That is weird ::slight_smile:

When I try in Eclipse, I get the expected 2 classes (so not the Outer$1 class), but using javac I get the weird 3rd one…

1.4.2 beta also generates that $1 class. Eclipse 2.1 doesn’t. The eclipse-generated Outer$Inner class has just one constructor:

Outer$Inner(Outer o) {
  super();
  this$0 = o;
}

javac probably wants to make sure to create a unique method signature but I don’t really know why.

It’s a class generated to send information to the CIA. That’s why when you decompile it you dont see anything. True story

It’s a “go between” class that links used methods and variables between the internal and parent classes. Since your example doesn’t actually access anything inside internal class or vica-versa, the “go between” is unnecessary. Javac usually generates it anyway. I’ll make a bet that Eclipse is using Jikes instead.

Ah, good. I won’t worry about it then.

I was developing an ultra-clever DisplayMode filtering class and had a load of anonymous inner classes at one point. I then removed them all in favour of one named inner class. But one unnamed class file remained…

I have noticed that it doesn’t appear if the inner class is anything but private though. I must decompile the classes and see what goes on in that case.

Cheers, everyone!