[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: Language War (Re: "C" Manual)



Lo, on Friday, January 4, David Jardine did write:

> On Thu, Jan 03, 2002 at 05:34:00PM -0600, Richard Cobbe wrote:
> > 
> > Yes, it *is* types.  Remember the definition of type-safety:
> > 
> >     If an expression E is determined at compile time to have type T,
> >     then evaluating E will have one of two results:
> > 
> >         1) The value of E is a valid object of type T and not just some
> >            random collection of bits we're misinterpreting as a T.
> >         2) a well-defined runtime error occurs (e.g., Java's
> >            ArrayBoundsException).
> > 
> An ArrayBoundsException is not a question of type in Java.  An
> array of two chars is exactly the same type as an array of two
> thousand chars.  A two-dimensional array of chars, on the other
> hand, is a different type from a three-dimensional one.

Consider the Java declaration
    int a[]

The issue above is not the type of a, but rather the type of a[45].
The compiler determines that a[45] has type int---try passing it as an
argument to a method that expects a string, and you'll get a compilation
error, regardless of the actual number of elements in a.

Since the compiler has determined a[45] to have type int, then
evaluating that expression better darned well produce a real-live int.
If it can't (because a only has 4 elements), then, to preserve
type-safety, Java signals an error.

Richard



Reply to: