Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "val$title" (dollar sign in expression) in Java?

Tags:

java

swing

private void launchEventPanel(String title) {
    EventQueue.invokeLater(new Runnable(title) {
        public void run() {
            JFrame myFrame = new JFrame();
            myFrame.setTitle(this.val$title);
            myFrame.setIconImage(CrConference.this.mainCore.myPanel.myIconManager.getPromptIcon(Mart.class.toString()));
            myFrame.getContentPane().add(Conference.this.myEventPanel, "Center");
            myFrame.pack();
            myFrame.setVisible(true);
        }
    });
}

i got some code that i am trying to compile and understand. help highly appreciated

like image 463
java-learner Avatar asked Apr 05 '12 18:04

java-learner


1 Answers

As described here and here, the argument to the Runnable constuctor and "this.val$" to the field name is added by the compiler and shows up in the generated bytecode. Hence these extra things are reflected in the decompiled code.

To get the original decompiled code, add final to the declaration of title and remove title from the call to Runnable and the this.val$ from in front of title:

private void launchEventPanel(final String title) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            JFrame myFrame = new JFrame();
            myFrame.setTitle(title);
            myFrame.setIconImage(CrConference.this.mainCore.myPanel.myIconManager.getPromptIcon(Mart.class.toString()));
            myFrame.getContentPane().add(Conference.this.myEventPanel, "Center");
            myFrame.pack();
            myFrame.setVisible(true);
        }
    });
}
like image 146
Tim Lewis Avatar answered Sep 24 '22 11:09

Tim Lewis