-1

I am a newbie to java, i want to learn about the native typesafe enum patterns? can anybody help me?

thanks in advance..

Mud Hut
  • 575
  • 2
  • 10
  • 21
  • Do you have a specific question about how to use them? – Peter Lawrey Oct 22 '12 at 10:16
  • 1
    http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html – assylias Oct 22 '12 at 10:18
  • i want to know the difference between typesafe enum patterns and native type-safe enum patterns. – Mud Hut Oct 22 '12 at 10:19
  • 1
    @ChandanMithun: What do you mean by "...typesafe enum patterns..." and "...native type-safe enum patterns..."? The best practice and pattern for enums in Java is to use the built-in (is that what you mean by "native"?) `enum` concept, which has been in the language for years. – T.J. Crowder Oct 22 '12 at 10:22
  • @T.J.Crowder Thank you, now i got the clear understanding – Mud Hut Oct 22 '12 at 10:32
  • See http://stackoverflow.com/questions/5092015/advantages-of-javas-enum-over-the-old-typesafe-enum-pattern – Jesper Oct 22 '12 at 11:32
  • See http://stackoverflow.com/questions/4709175/why-and-what-for-java-enum – Jesper Oct 22 '12 at 11:33

2 Answers2

1

Use enums; details in the JLS.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Sending a *newbie* to the JLS is not going to help him very much! – assylias Oct 22 '12 at 10:19
  • @assylias: I'm not sure I agree, if more people read the JLS early on... :-) But in any case, pointing out that Java has `enum` as a first-class concept (now) should be helpful. – T.J. Crowder Oct 22 '12 at 10:20
0

i want to know the difference between typesafe enum patterns and native type-safe enum patterns.

A type-safe enum pattern is a design / implementation pattern that provides something similar to native enums. Since, Java 5.0 and later support native enum types (tutorial link), there is no real need to know how to do this. Just use native enum types.

If you are curious about how it used to be done, read this: Alternative to enum in Java 1.4

(A native typesafe enum pattern is a contradiction in terms. Java's native enum construct is a first class programming language construct ... not a design pattern.)

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216