java - I'm confused about the basics of pointers/references -
given this:
int = 10; int b = a; a++;
is b = 10 or 11? if 10, why happen (i'm using android example):
textview x = new textview(); textview y = x; x.settext("abcde");
which leads y's text being set "abcde", doesn't it?
edit:
what if use 'integer' instead of 'int'? b = 11?
an int
primitive, a
, b
don't refer object, hold value. therefore assignment int b = a;
copies original value of a
b
, a++
modifies a
.
with reference types, behavior different, shown in textview
snippet. x
, y
refer same textview
instance (object), x.settext("abcde")
modifies single instance referred both.
Comments
Post a Comment