Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is Enum

 
jacob deiter
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

CAn anyone explain about "Enum" in ?.I read some some article but i could not get the correct point.

2) I like to have a varialbe which contain 4 or 5 element ,at runtime i will give value for this variable,For example
variable loom ,it has elements color,manufacture,....).PLease explain ,how can i create variable which has many elements
 
f. nikita thomas
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


if you look closely it's kinda like a class! it has fields and methods to change behavior. like everything else in java Enum's are zero indexed so ...



which could come in pretty handy when you're trying to index a data structure like and array or vector. finally if you look at the PaperCurrency Enum we actually can add a value to the element; in this case the primitive (int). the field:



refers to the value stored in each element ie One(1), Five(5), etc.

the accessor method getValue() returns these when called on the appropriate element. since Enums are object you can test for uniqueness with instanceof. i hope this helps a little.
[ April 15, 2008: Message edited by: f. nikita thomas ]
 
Rodrigo Lopes
Ranch Hand
Posts: 119
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An enum is a type whose fields consist of a fixed set of constants. Enums were introduced in Java 5.0. If you are using a version lower than JDK 1.5 then you won't be able to harness the power of enums.

Please visit this link for details on enums.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic