zoukankan      html  css  js  c++  java
  • Eclipse常用的6个Debug技巧

    1. Ctrl+Shift+i:

     1 Person father = new Person();
     2 father.setName("father");
     3 System.out.println(father.getName());
     4         
     5 Person children = new Person();
     6 children.setName("children");
     7 father.setChildren(children);
     8 if (father.getChildren().getName() != null) {
     9     System.out.println(father.getChildren().getName());
    10 }

    假如我只想看father.getChildren()的结果是不是为空,那么就可以在debug模式下选中father.getChildren(),然后按Ctrl+Shift+i就可以查看其结果。

    2. 查看数据结构

    1 Map<Integer, String> map = new HashMap<Integer, String>();
    2 map.put(1, "一");
    3 map.put(2, "二");
    4 map.put(3, "三");
    5 map.put(4, "四");
    6 map.put(5, "五");

    想查看map的数据结构,可以点击这里切换视图进行查看

    3. 条件Debug

    1 for (int i=1; i<11; i++) {
    2     System.out.print(i + "	");
    3 }

    假如只想在i=7的时候断住,就可以在第二行下断点,然后右击断点,选择:Breakpoint Properties

    debug运行,可以看到1-6已经打印出来,在i=7的时候被断住了

     4. 异常断点

    1 System.out.println(1/0);

    点击debug窗口的这个按钮

    添加相应的异常类

    debug运行,被断住

    5. expressions

    1 Person father = new Person();
    2 father.setName("father");

    expressions窗口可以定向查询你想要看到的东西,例如这里你想看father对象的名称,可以的expressions窗口输入father.getName(),回车就可以看见相应的值:

    6. display:

    该窗口下可以对相应的代码进行更改,例如对father对象的名称进行更改,可以在display窗口输入:father.setName("test"),然后选中该代码,点击这个按钮然后你会发现该值已经改变了

    当然也可以对值进行输出

    作者:Oven
    个人网站:http://www.cloveaire.com
    个性签名:大亨以正,莫退初心!
    如果觉得这篇文章对你有帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
  • 相关阅读:
    避免数据脏读
    OGG配置文件中参数化的运用
    GoldenGate基于中间队列文件的初始化
    一次linux中毒,挖矿病毒
    goldengate新版本中查看日志读取点
    dlopen用法参数flag介绍
    gdb调试带参数和调试core
    在现有的git服务器上面创建新的repo
    Play Old Diablo 2 on macOS Catalina
    Odoo中的Environment对象
  • 原文地址:https://www.cnblogs.com/Oven5217/p/6713623.html
Copyright © 2011-2022 走看看