java - 为什么调试指针移动到源方法的第一行,而不是移动到当前存在调试指针的方法的第一行?

标签 java

什么情况下 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);
    }
}

第 2 类:

public class BeanClass {

    private boolean result = false;

    public boolean getResult() {
    return result;
    }

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

预期场景:当在当前存在调试指针的方法中编辑并保存一段代码时,调试指针应移动到当前存在调试指针的方法的第一行存在。

实际场景:当一段代码被编辑并保存在当前存在调试指针的方法中时,调试指针将移动到源方法的第一行,而不是移动到源方法的第一行调试指针当前所在的方法。

最佳答案

在调试期间更改代码将使该方法从头开始重新执行,因为它必须重置该方法中的局部变量。 有关其工作原理或如何正确使用调试选项的更多详细信息,请参阅下面的链接。 http://www.ibm.com/developerworks/library/os-ecbug/

If you are running Java Virtual Machine (JVM) V1.4 or higher, Eclipse supports a feature called Hotswap Bug Fixing (not available in JVM V1.3 or lower). It allows the changing of source code during a debugger session, which is better than exiting the application, changing the code, recompiling, then starting another debugging session. To use this function, simply change the code in the editor and resume debugging

还有一件事:在调试时,只需更改任何代码并保存它,eclipse就会自动将修改后的代码传输到目标VM。 请注意,您无法对代码进行结构性更改,例如添加新方法、更改方法签名或添加新字段。但您可以更改方法内的代码。

关于java - 为什么调试指针移动到源方法的第一行,而不是移动到当前存在调试指针的方法的第一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42273420/

相关文章:

java - 从 String 到 byte[] 到 String 的转换

java - 为什么 VisualVM 中的 CPU 时间不加起来?

Java 日历问题

java - 如何为我的 Spring 3/Hibernate 4 LocalSessionFactoryBean 设置事件监听器?

java - 如果使用 spring AuthenticationProcessingFilter 扩展类,则无法在 jpa 中保留实体

java - "||"和循环哪个更有效?

java - 找不到hibernate.cfg.xml

java - 创建表后立即插入行 - Oracle

java.lang.OutOfMemoryError : PermGen space, 我在 Mac Os 上使用 tomcat

java - 你如何通过 2 个 Activity 传递一个字符串?