Understanding the 'finally' block

后端 未结 6 1003
误落风尘
误落风尘 2021-01-13 04:23

I\'ve written seven test cases for understanding the behavior of the finally block. What is the logic behind how finally works?

pac         


        
6条回答
  •  日久生厌
    2021-01-13 04:46

    Why builder = null is not working?
    Because you are setting the local reference to null which will not change the content of the memory. So it is working, if you try to access the builder after finally block then you'll get null.
    Why builder.append("+1") work?
    Because you are modifying the content of the memory using the reference,that's why it should work.
    Why count++ does not work in testFive()?
    It is working fine with me. It outputs 100 as expected.

提交回复
热议问题