The $ sign is used by the Java compiler for the generated names of inner classes, synthetic fields, and methods. It is valid for identifiers in a Java source, but discouraged.
The code you show looks like decompiled code of an anonymous inner class. The anonymous Runnable implementation in the updateHtmlEditor method accesses the parameters of its surrounding method. To make access available, parameters must be declared final . In Java byte code, an anonymous class has three attributes of the final instance, this$0 , which contains the external instance of LinkParser.this , val$editorkit and val$reader , which contains the parameters of the external method, and a constructor with three arguments that assigns its arguments attributes.
Note that LinkParser.this.htmlViewEditor is a reference to an attribute of the external LinkParser class. In this example, an explicit reference to an external instance of LinkParser.this may be omitted.
The source code looks something like this:
private synchronized void updateHtmlEditor(final HTMLEditorKit editorkit, final StringReader reader) { Runnable runnable = new Runnable() { public void run() { try { editorkit.read(reader, htmlViewEditor.getDocument(), htmlViewEditor.getDocument().getLength()); } catch (IOException ex) { Logger.getLogger(LinkParser.class.getName()).log(Level.SEVERE, null, ex); } catch (BadLocationException ex) { Logger.getLogger(LinkParser.class.getName()).log(Level.SEVERE, null, ex); } } }; SwingUtilities.invokeLater(runnable); }
Christian semrau
source share