Java's static typesystem
Francois-Rene Rideau
Francois-Rene Rideau <fare@tunes.org>
Fri Nov 9 11:33:02 2001
Ok, it looks like what I have said about Java is misleading at best.
The places where Java's static type system are allegedly weak include:
* Typecasting an object along its class hierarchy.
This introduces a discrepancy between the real runtime type of the object
and its declared static type (which will be a superclass of its real class),
but no illegal operation or discrepancy in method called can result of it;
along various casts, the object's declared type can only be changed to a
superclass of its actual class (otherwise, an exception is raised
*at runtime*).
* the NULL object is a bit of a monster in the typesystem, since it can be
used almost anywhere, and can be used to trigger different static methods
in different contexts. However, once again, the semantics of it are clear,
whether used with dynamic methods (that will cause a runtime exception) or
with static methods (whose semantics is known at compile-time).
All in all, Java's static type system can be considered strong.
However, this forces to reconsider the system so as to account for
dynamic type behaviour, which makes it less of a static typesystem
(or a system with weaker static invariants) than that of, say, Haskell.
In absence of a formal definition of what is or isn't a *strong static*
type system, my conclusion would be that the oppositions static/dynamic,
strong/weak, inferred/declared can be more usefully seen as intentional
oppositions (and not orthogonal ones, at that) rather than formal features
that could be checked by looking at the language specification.
Yours freely,
[ François-René ÐVB Rideau | Reflection&Cybernethics | http://fare.tunes.org ]
[ TUNES project for a Free Reflective Computing System | http://tunes.org ]
"The society which scorns excellence in plumbing as a humble activity
and tolerates shoddiness in philosophy because it is an exaulted
activity will have neither good plumbing nor good philosophy.
Neither its pipes nor its theories will hold water."