Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

jave 5.0 - enum can I assign values?

Thread view: 
timasmith@hotmail.com - 15 Jul 2006 01:41 GMT
per
http://java.sun.com/developer/technicalArticles/releases/j2se15langfeat/

there was an example of implementing enums prior to 5.0  (see below).

In 5.0 you have enum which is sweet for assigning arbitraty values but
I want to assign specific values and gain all of the other benefits of
using an enum...

so I want (can I have...?)

    enum ASC {abc=3,ced=4};

and if you look at the cited pre 1.5 example you have that same
flexibility

public class MainMenu {
 private final String name;

 private MainMenu(String name) {
   this.name = name;
 }

 public static final MainMenu FILE = new MainMenu("file");
 public static final MainMenu EDIT = new MainMenu("edit");
 public static final MainMenu FORMAT = new MainMenu("format");
 public static final MainMenu VIEW = new MainMenu("view");

 public String toString() {
   return name;
 }
}
Roland de Ruiter - 15 Jul 2006 10:41 GMT
> per
> http://java.sun.com/developer/technicalArticles/releases/j2se15langfeat/
[quoted text clipped - 12 lines]
> flexibility
> [...]

public enum ASC {
    abc(3), ced(4);

    private final int foo;

    private ASC(int bar) {
        this.foo = bar;
    }

    public int getFoo() {
        return foo;
    }

    public static void main(String[] args) {
        for (ASC asc : ASC.values()) {
            System.out.println(asc + ".getFoo()=" + asc.getFoo());
        }
    }
}
<http://java.sun.com/docs/books/tutorial/java/javaOO/enum.html>
Signature

Regards,

Roland



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.