On 08/22/2012 02:45 PM, lipska the kat wrote: > On 22/08/12 20:03, Evan Driscoll wrote: >> Second, this concept isn't *so* unfamiliar to you. If I give you the >> following Java code: >> >> void foo(Object o) { ... } >> > looking at this method declaration I can see that the method takes an > argument of type Object (and just FYI class Object is not abstract and > you can do Object o = new Object()) and does not return a value. > I know that for the lifetime of this JVM, whatever o turns out to be it > will always be an Object. I can't assign a primitive to o as ints chars > floats etc are certainly not Objects. There are certain invariants that > give me a warm and comfortable feeling inside.
I'm not saying it's nothing, but "can't assign a primitive" isn't much of an invariant in the broad scheme of things when you can pass items as diverse as lists, GUI buttons, files, etc. I would say it's more like if you see 'int x' then *that* imposes a pretty big invariant, but passing 'Object' imposes almost nothing. This is especially true considering the fact that you actually *can* say 'foo(4)' and Java will go and autobox the 4 into Integer(4) for you. (BTW, this analogy suggests a way that's actually fairly useful for how to look at Python coming from the Java perspective: Python just lacks primitive types and things like integers are always boxed. Thus *all* Python variables are essentially references.) Evan
signature.asc
Description: OpenPGP digital signature
-- http://mail.python.org/mailman/listinfo/python-list