2017-02-16 28 views
0

在以下情況下Eclipse Debugger發生了什麼情況?爲什麼調試指針移動到源方法的第一行而不是移動到調試指針當前存在的方法的第一行?

第1類:

public class Sample { 
    public static void sourceMethod(BeanClass bean, Map<String, List<String>> hmMap){ 
     try { 
      System.out.println(); 
      enterData(bean, hmMap); 
     } catch (Exception e) { 
      e.getMessage(); 
     } 
    } 

    public static void enterData(BeanClass bean, Map<String, List<String>> hmMap){ 
     try { 
      System.out.println("hello");//Comment or Uncomment this line while debugging 
      System.out.println("Value : "+hmMap.get("KeyValue").get(0)); 
      bean.setResult(true); 
     } catch (Exception e) { 
      e.printStackTrace(); 
      bean.setResult(false); 
     } 
    } 

    public static void main(String args[]){ 
     BeanClass bean = new BeanClass(); 
     Map<String, List<String>> hmMap = new HashMap<String, List<String>>(); 
     List<String> list = new ArrayList<String>(); 
     list.add("hi"); 
     list.add("hello"); 
     hmMap.put("KeyValue", list); 
     Sample.sourceMethod(bean, hmMap); 
    } 
} 

二級:

public class BeanClass { 

    private boolean result = false; 

    public boolean getResult() { 
    return result; 
    } 

    public void setResult(boolean setResult) { 
    this.result = setResult; 
    } 
} 

預期方案:當一段代碼被編輯並保存在所述調試指針是當前存在,則方法調試指針應該移動到調試指針當前所在方法的第一行。

實際場景:當一段代碼被編輯並保存在所述調試指針是當前存在的方法則調試指針移動到源方法的第一行,而不是移動到方法,其中調試的第一線指針當前存在。

+1

對我來說,它按預期工作,Eclipse 4.6 – Zefick

+0

@ChrisH編輯代碼並簡化代碼!更新了上面的代碼。 –

+0

@Zefick嘗試更新的代碼! –

回答

2

在調試過程中更改代碼會使該方法從頭開始重新執行,因爲它必須重置該方法中的局部變量。 有關它如何工作或如何使用調試選項正確引用以下鏈接更多的細節.. http://www.ibm.com/developerworks/library/os-ecbug/

如果你正在運行的Java虛擬機(JVM)V1.4或更高時,Eclipse 支持功能稱爲Hotswap Bug修復(不適用於JVM V1.3或更低版本)。它允許在 調試程序會話期間更改源代碼,這比退出應用程序更好, 更改代碼,重新編譯,然後開始另一個調試會話。要使用此功能,只需更改代碼編輯器 和恢復調試

一件事:雖然調試,只需更改任何代碼,並保存它時,Eclipse會自動將修改後的代碼傳送到目標VM。 請注意,您無法對代碼進行結構更改,例如添加新方法,更改方法簽名或添加新字段。但是你可以改變方法中的代碼。

相關問題