4 ms·
> Yet you can absolutely write: > String str = "hello,"; > str += "world!"; So it's "immutable" for some lawyerish definition which does me no good. `str` is a
by kbp 8y ago
> Yet you can absolutely write: > String str = "hello,"; > str += "world!"; So
it's "immutable" for some lawyerish definition which does me no good.
`str` is a mutable reference to an immutable object. You can make the
reference point to something else, but the object being pointed to is
immutable, so eg if you pass it to a function, that function cannot change it
under you. If you want to make the reference immutable, declare it as final. I
don't think understanding the difference between a pointer and the value it
points to is lawyerish.
- mrkeen 8y agoThank you. ^ that's the lawyerish definition I was referring to ^
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]