Code:
BigDecimal bd = new BigDecimal("1");
System.out.println(bd.toString());
problem description:
I have run the above code in JDK1.7 1.8.9.0, and the result is the same. Normally, the printed result of this code should be 1. But when I hit a breakpoint at line 428 of the source code of the BigDecimal class, and then after idea runs through debug (at the breakpoint, just skip execution), the print result becomes 0.
I am curious about this result. Looking at the toString source code of BigDecimal, I find that when debug starts to execute the BegDecimal constructor, the value of the stringCache variable becomes "0", leading to the toString () result of 0.
I am confused about this result. I"d like to ask the god to help me answer.
Note: the code in line 428 of BigDecimal is
if (offset + len > in.length in the constructor of BigDecimal class | | offset < 0)
this line of code