Are Java primitives immutable?

前端 未结 6 1938
野的像风
野的像风 2020-12-04 23:55

If a method has a local variable i:

int i = 10;

and then I assign a new value:

i = 11;

Will

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-05 00:19

    Yes, they are immutable. They're totally unchangeable.

    There's a nice explanation buried in here. It's for Go, but it's the same thing in Java. Or any other language in the C family.

提交回复
热议问题