6
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

java-learner
  • 79
  • 2
  • 6
  • http://stackoverflow.com/questions/65475/valid-characters-in-a-java-class-name , http://stackoverflow.com/questions/5845299/why-is-it-bad-to-start-a-variable-name-with-a-dollar-sign-in-c-java-and-simila , http://stackoverflow.com/questions/1987603/is-there-a-convention-when-using-java-rmi-to-use-the-dollar-sign-in-a-variab –  Apr 05 '12 at 18:29
  • 2
    Is this decompiled code? I would expect variable names like that in decompiled code. – Jesper Apr 05 '12 at 18:30
  • I have edited the title to reflect the "odd code", `val$title` a perfectly valid Java identifier -- it's just as valid as `foobar` -- but the "rule" is to not use it (except tools that generate code automatically). –  Apr 05 '12 at 18:31

3 Answers3

4

This line:

myFrame.setTitle(this.val$title);

Is simply setting the title of a JFrame object, using the value of the attribute val$title for doing so. val$title is an instance attribute of the current class, its name is a bit unusual (because of the $) but nevertheless, valid for an identifier in Java.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
4

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);
        }
    });
}
Tim Lewis
  • 3,335
  • 1
  • 36
  • 26
2

line 5 is just setting the title of the frame (the text you see on the top of the window frame in windows) "this.val$title" is just a local memeber named val$title that whoever wrote the code stored the title string in.

While it is a bit uncommon to see most languages based on C treat $ as an alphapetic character, like a-z or A-Z.

tletnes
  • 1,958
  • 10
  • 30
  • Languages *loosely* based on C, or that use C-like *syntax*, maybe. C itself doesn't, nor does C++ AFAIK. JS and Java are the only C-alikes i can think of of that do, actually. – cHao Nov 27 '12 at 18:23