You are not logged in.

#1 2007-08-07 18:34:57

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

(Java) Access synthetic methods generated from inner classes

I've asked this question on another forum too, but I know that there are quite a lot of programmers here so maybe some of them can give an insight on this:

I was wondering, is it possible to access these methods? For example, I've got this method in OwnFrame.java:

private WindowAdapter getWindowDestroyer()
{
    return new WindowAdapter()
    {
        @Override
        public void windowClosing(WindowEvent e)
        {
            System.out.println(button.toString());
            System.exit(0);
        }
    };
}

And this generates a synthetic method in OwnFrame.class to access the button variable which is private from the class OwnFrame$1.class, javap output for this method:

static javax.swing.JButton access$0(sandBox.OwnFrame);
  Code:             
   0:   aload_0     
   1:   getfield        #78; //Field button:Ljavax/swing/JButton;
   4:   areturn

Now can I access this method from another class in the same package? I tried the following:

System.out.println(OwnFrame.access$0(new OwnFrame()));

But that gives me this compiler error:

symbol  : method access$0(sandBox.OwnFrame)
location: class sandBox.OwnFrame
                System.out.println(OwnFrame.access$0(new OwnFrame()));
                                           ^
1 error

Does anyone know whether and how I can access the button field through this synthetic method?

Offline

Board footer

Powered by FluxBB