Re:What is type safety?
by AnimalMuppet on Tuesday August 05, 2014 @01:35PM
(#8138173)
Java's casting is not totally statically type checked. IIRC, the behavior at runtime is very clear, though - you either get a successful cast, if the object you're casting really is an instance of what you're trying to cast it to, or else you get a ClassCastException (from memory, actual name may vary).
That's not totally static, but within the definitions of the article, it might be good enough to count as "type safety" without falling into the "null type safety" category.
Re:What is type safety?
by marcosdumay on Tuesday August 05, 2014 @01:30PM
(#8138128)
Well, "strict" might be a better name for your "strong".
I don't think it's any less precise a concept. Java type system is less strict than Haskell's, has similar "strictiness" to Python or Ruby (while quite different in static typing), and is more strict than C, or Perl.
Type casting has to be modeled (more or less) as (a) upcasting only (b) a failure of type safety, or (b) an admission that the type system is entirely vacuous.
Re:What is type safety?
by AnimalMuppet on Tuesday August 05, 2014 @01:38PM
(#8138187)
No, you can have downcasting that is checked for validity at runtime, a la Java (or C++ with RTTI). This is not a failure of type safety, since only valid casts will be performed. It's not vacuous, either - it's not just one big type.
What happens when a cast is invalid?
You have type-safe casts in Haskell, for instance, where the failure is reflected at runtime.
cast :: (Typeable a, Typeable b) => a -> Maybe b
Those are alright.
Re:What is type safety?
by AnimalMuppet on Tuesday August 05, 2014 @03:24PM
(#8138798)
In Java, IIRC, the cast fails with a ClassCastException. That seems to me to be "failure is reflected at runtime".
In C++ with RTTI, IIRC it returns null. That's also "failure at runtime" (of a sort), but you have to check it.
RTTI returns nullptr when casting a pointer, but it does throw an exception when casting references. Both of these behaviors are well-defined, although the first is kind of questionable.
Haskell also uses type inference rather than requiring type declarations, but that is not _directly_ related.