• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What does "type-safe" really mean?

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Thanks
Pho
 
Junilu Lacar
Bartender
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic