Are Java primitives immutable?

前端 未结 6 1936
野的像风
野的像风 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:10

    Primitive literals and final primitive variables are immutable. Not final primitive variables are mutable.

    Identity of any primitive variable is the name of that variable and it's obvious that such an identity is unchangeable.

提交回复
热议问题