This article introduces the method of changing the values of various types of variables in IDEA Debug mode. It is shared with you. The details are as follows:
Test class
import org.slf4j.LoggerFactory;import java.util.HashMap;import java.util.Map;/** * Created by PengHongfu 2018-04-18 18:21 */public class testClass { private static final org.slf4j.Logger logger = LoggerFactory .getLogger(testClass.class); public static void main(String args[]){ int a = 11; Map<String,Object> map = new HashMap<>(); map.put("name","Pi"); map.put("age",20); logger.info("a={},map={}",a,map); }}In
debugmode, after setting断点, the original value of variableain the figure above11Click the green "+" sign inWatchs, enter the expressiona=22, and execute it downwards. You can find that the value ofabecomes22.
For special types such as
Map,List, etc., you can also assign values in a similar way tomap.put("name","Hali").
com.ycjf.ycs.service.khgl.wxzlgl.testClass - a=22,map={name=Hali, age=20} Note: The priority of expressions in Watchs is higher than that in the code
In the example, map.put("name","Hali") in Watchs is defined before the code map.put("name","Pi") is executed. name value in map is Hali throughout debug period and will not be overwritten by the code map.put("name","Pi") .
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.