2012-02-04 42 views
7

我到處找試圖找出什麼是VAL $的EditorKit或以下手段$符號,但沒有運氣......請幫助Java代碼來看看......

private synchronized void updateHtmlEditor(HTMLEditorKit editorkit, StringReader reader) 
    { 
    Runnable runnable = new Runnable(editorkit, reader) 
    { 
     public void run() { 
     try { 
      this.val$editorkit.read(this.val$reader, LinkParser.this.htmlViewEditor.getDocument(), LinkParser.this.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); 
    } 
+4

這是一個反編譯的代碼? – Natix 2012-02-04 16:39:58

回答

3

$符號是爲內部類,合成的字段和方法所產生的名稱中使用由Java編譯器。它對Java源代碼中的標識符有效,但不鼓勵。

告訴你的代碼看起來像一個匿名內部類的反編譯的代碼。該方法updateHtmlEditor內的匿名Runnable執行訪問其周圍方法的參數。爲了使訪問成爲可能,需要聲明參數final。在Java字節碼中,匿名類具有三個最終實例屬性,this$0包含包含外部方法參數的外部實例LinkParser.this,val$editorkitval$reader以及具有三個參數的構造函數,該參數將其參數分配給屬性。也

注意LinkParser.this.htmlViewEditor是外部類,LinkParser的屬性的參考。在此示例中,可以省略對外部實例LinkParser.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); 
    } 
+0

謝謝你們的幫助...... – scamexdotexe 2012-02-05 06:31:46

15

這並不意味着什麼特別的 - 它只是形成名稱的一部分,酷似l之前或之後e的一封信。

參見Identifiers的JLS部分,瞭解什麼是和一個名稱是不允許的全部細節。

4

我們真的不能告訴我猜,因爲你沒有提供的變量聲明,但在Java中$可以是一個變量名的一部分,比如,你可以做一些事情,像這樣:

String str$rr = "Hello"; 
System.out.println(str$rr); 

類似的東西會打印Hello