It's not a secret anymore!
The moose likes Beginning Java and the fly likes What does Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What does "type-safe" really mean?" Watch "What does "type-safe" really mean?" New topic

What does "type-safe" really mean?

Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 782

Context usage: "A type-safe enum pattern".
My understanding of the term "type-safe" is that
if a method expect type A, the compiler will throw
an exception is a term that is not assignable to A
is passed in? Any other characteristics?


Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

The compiler will also be able to catch an invalid assignment of the enumerated type to a variable of another type and vice versa.
These "pros" of typesafe enums are from "Effective Java" by Joshua Bloch:
- Constants may be added to a typesafe enum without recompiling its clients because the public static object reference fields containing the enumeration constants provide a layer of insulation between client and the enum class.
- Because they are full-fledged classes, you can override the toString method, internationalize them, or augment them with any method that seems appropriate.

Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform

Junilu - [How to Ask Questions] [How to Answer Questions]
I agree. Here's the link:
subject: What does "type-safe" really mean?
jQuery in Action, 3rd edition