The meaning of a = b in object oriented languages
Ken Bloom
kbloom at gmail.com
Wed Sep 19 11:38:07 EDT 2007
On Tue, 18 Sep 2007 18:02:59 -0400, Lew wrote:
> Summercool wrote:
>> when a writing or a book reads "a is a Hash object; a is an Array
>> object; or a is an Animal object" it is just a short form to say that
>> "a is a reference to that object."
>>
>> b = a means "whatever a is referencing to, now b is referencing it
>> too".
>>
>> so that's why a[1] = "foobar" will change what b will display, but a
>> = "foobar" will not change what b will display.
>
> You can't do both in Java. Is a an array or a String? If a is a String
> and b is an array, then neither `a = b' nor `b = a' will compile in
> Java.
>
> Java is a strongly-typed, compiled language which means it does more
> static type checking and thus would reject treating a as both an array
> and a String.
> In that environment the programmer must choose one or the other.
In this Java example, a and b are statically typed to be of type Object.
Both Strings and Arrays descend from Object. (And primatives like
integers and the like will be autoboxed into descendants of Object).
--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/
More information about the Python-list
mailing list