why python annoys me

D-Man dsh8290 at rit.edu
Thu Apr 19 14:07:13 EDT 2001


On Thu, Apr 19, 2001 at 01:35:10PM +0200, Alex Martelli wrote:
| "D-Man" <dsh8290 at rit.edu> wrote in message
<java arrays>
| > They are objects (of a sort, more like a C struct IMO), but they do
| > not inherit from java.lang.Object and thus can't be passed to a method
| > that wants a java.lang.Object.
| 
| Not in the Java I know.

I just checked with a compiler, and you are right.  I don't know why I
thought they were so different.

| > Also where is the inheritance hierarchy for arrays you mentioned?
| 
| In Java, if X inherits from Y, then array-of-X inherits from array-of-Y.

I wasn't thinking of that.

| This, given mutability, is unfortunately wrong, and breaches Java's
| compile-time type-safety: you can pass an array-of-X to a method
| as an array-of-Y argument, and the method then tries to stick into
| the array a Y instance (compile-time correct) that is not an X --
| and you get a runtime type violation (specs mandate that a specific
| exception be raised for this, fortunately, so you don't get random
| undiagnosed errors as you might for similar array bloopers in C++).

(Python) lists are much better (also with runtime lookups, rather than
compile-time constant offsets) :-).

-D





More information about the Python-list mailing list