Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Enumeration.  RSS feed

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to write a code on enumeration with constructor but it is giving error.
// practice enumarations along with constructors.

enum ek
{
ff(ff),aa(aa),bb(bb),cc(cc),dd(dd),ss();
ek(String ls)
{
System.out.println("The current enum is "+ ls);
}
ek()
{
System.out.println("The value is " + "arbit");
}
}

public class enumB // here I am trying to call the
{
public static void main(String a[])
{
ek e;
e = ek.aa(aa);
//ek();
}
}

Now this is giving enormous error(I am bit ashamed while saying so).

But I have tried to do the same code with a bit change now it is working!
// practice enumarations along with constructors.

enum ek
{
aa;
}

public class enumB
{
public static void main(String a[])
{
ek e;
e = ek.aa;
if(e == ek.aa) // make a small note when to use
{
System.out.println("It is working");
}
//ek();
}
}
The main issue is with the constructors. I am unable to use the constructors properly. Please suggest.

**
You might face some problem while reading the code, due to wrong indentation. I am trying to indent the code. While editing it is showing the proper indentation. But in view it is not.

[ May 25, 2007: Message edited by: babai bhaumik ]

[ May 25, 2007: Message edited by: babai bhaumik ]
[ May 25, 2007: Message edited by: babai bhaumik ]
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't create new enums at run-time.

little bit modified your version:
 
babai bhaumik
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,
Thanks for the reply.
I have done following changes in the program.


I was incorrectky mentioning the constructor parameters (in this case String), I was using String without "".
Adding that solved the problem.
Thanks a lot agin.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!