Instantiating enums

Hi!
I am curious why javac generates public constructors of enum classes making it possible to instatiate an enum using reflection. Here's an example:
// EnumX.java
public enum EnumX { A, B }// EnumTest.java
import java.util.EnumSet;
public class EnumTest {
    public static void main(String[] args) {
        try {
            EnumX e1;
            // e1 = new EnumX("C", 0);     // enum types may not be instantiated 
            e1 = EnumX.class.getConstructor(String.class, int.class)
                    .newInstance("C", 0);  // no problem here
            System.out.println(e1);        // prints C
            for (EnumX e : EnumSet.of(e1)) {
                System.out.println(e);     // prints A
        } catch (Exception e) {
            e.printStackTrace();
}Is it my misunderstanding of specification or a bug in compiler?
Jurek

javac did that because that's what the spec required at the time. Since then jsr201 has addressed this issue. Enum constructors will be private, and will not be callable via reflection. This change will be in beta2.

Similar Messages

  • Dynamic enum instantiation and access

    Here's what I would like to do, but I'm not sure if/how it can be done.
    Given a set of enum's e1, e2, e3;
    1. Specify at runtime the enum I'm interested in as a string "e1".
    2. Dynamically create an object of that type.
    3. Access the values() method at runtime to see what the constants of e1 are.
    I can get this far:
    String className = new String("e1");
    Class c = Class.forName(className);
    Object o = c.newInstance();Step #3 is the issue. I don't know how to cast the object in order to get access to the values() method. The Enum class does not include that method. Anyone know what does that I can cast my object to?
    Thanks,
    Mark

    import java.util.EnumSet;
    * @since October 10, 2006, 12:41 PM
    * @author Ian Schneider
    public enum DynamicEnumAccess {
        A,B,C,D,E,F,G;
        public static void main(String[] args) throws Exception {
            Class<? extends Enum> e = (Class<? extends Enum>) Class.forName("DynamicEnumAccess");
            EnumSet allOf = EnumSet.allOf(e);
            System.out.println(allOf);
    }

  • Test coverage of switch when using an enum

    I'm writing a unit test for the following: -
    switch (status) {
        case ACTIVE:
            return "A";
        case POSTED:
            return "P";
        default:
            throw new IllegalArgumentException("unknown status: " + status);
    }Where status variable is an enum type like: -
    public enum BatchStatus {
        ACTIVE, POSTED
    }I'm of the opinion that having the default branch above makes the code safer and more robust (it means that if the enum grows, problems can be immediately identified).
    So the question is... is it impossible to achieve 100% test coverage, but still retain the default branch above? Since the BatchStatus is an enum (and hence final, and cannot be instantiated), I can't create a third mock value that is neither ACTIVE nor POSTED, so I can't test the default branch.
    ???

    rather than use the switch block - which isn't very OO, and is a maintenance pain - why not have the enum itself return these values?
    public enum BatchStatus {
    ACTIVE("A"),
    POSTED("P");
    private BatchStatus(String status) {
        this.status = status;
    private String status;
    public String getStatus() {
        return this.status;
    }that way, the maintenance programmers have no option but to keep the lot up to date. this over-simplified example probably doesn't address your real problem, but it might point you in a direction you hadn't considered before

  • POFing Enums... InstantiationException

    I'm getting this exception
    Exception in thread "Thread-1" (Wrapped) java.io.IOException: An exception occurred instantiating a PortableObject user type from a POF stream: type-id=10015, class-name=oms.grid.SendingType, exception=
    java.lang.InstantiationException: oms.grid.SendingType
            at com.tangosol.util.ExternalizableHelper.fromBinary(ExternalizableHelper.java:265)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.partitionedService.PartitionedCache$ConverterFromBinary.convert(PartitionedCache.CDB:4)
            at com.tangosol.util.ConverterCollections$ConverterInvocableMap.invoke(ConverterCollections.java:2281)
            at com.tangosol.util.ConverterCollections$ConverterNamedCache.invoke(ConverterCollections.java:2747)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.partitionedService.PartitionedCache$ViewMap.invoke(PartitionedCache.CDB:11)
            at com.tangosol.coherence.component.util.SafeNamedCache.invoke(SafeNamedCache.CDB:1)
            at coup.QueueReader.run(QueueReader.java:105)
            at java.lang.Thread.run(Thread.java:722)
    Caused by: java.io.IOException: An exception occurred instantiating a PortableObject user type from a POF stream: type-id=10015, class-name=oms.grid.SendingType, exception=java.lang.InstantiationException: oms.grid.SendingType
            at com.tangosol.io.pof.PortableObjectSerializer.deserialize(PortableObjectSerializer.java:122)
            at com.tangosol.io.pof.PofBufferReader.readAsObject(PofBufferReader.java:3306)
            at com.tangosol.io.pof.PofBufferReader.readAsObjectArray(PofBufferReader.java:3350)
            at com.tangosol.io.pof.PofBufferReader.readAsObject(PofBufferReader.java:2924)
            at com.tangosol.io.pof.PofBufferReader.readObject(PofBufferReader.java:2603)
            at com.tangosol.io.pof.ConfigurablePofContext.deserialize(ConfigurablePofContext.java:358)
            at com.tangosol.util.ExternalizableHelper.deserializeInternal(ExternalizableHelper.java:2745)
            at com.tangosol.util.ExternalizableHelper.fromBinary(ExternalizableHelper.java:261)
            ... 7 moremy SendingType.java file looks like
    package oms.grid;
    import com.tangosol.io.pof.PofReader;
    import com.tangosol.io.pof.PofWriter;
    import com.tangosol.io.pof.PortableObject;
    import java.io.IOException;
    public enum SendingType implements PortableObject {
        NEW_ORDER,
        CANCEL,
        REPLACE,
        IGNORE;
        public void readExternal(PofReader reader) throws IOException {
        public void writeExternal(PofWriter writer) throws IOException {
    }probably I'm making this too difficult, right?
    Thanks,
    Andrew

    We just use a generic serializer for all enums:
    public class EnumSerializer implements PofSerializer {
         @SuppressWarnings({ "rawtypes" })
         private final Class<Enum> type;
         private final Object[] enumValues;
         @SuppressWarnings({ "unchecked", "rawtypes" })
         public EnumSerializer(int typeId, Class<Enum> type) {
              try {
                   this.type = type;
                   enumValues = EnumSet.allOf(type).toArray();
              } catch(Throwable t) {
                   t.printStackTrace();
                   throw new RuntimeException(t);
        @Override
        public Object deserialize(PofReader in) throws IOException {
             try {
                  final int ordinal = in.readInt(0);
                  try {
                       return enumValues[ordinal];
                  } catch(ArrayIndexOutOfBoundsException e) {
                       throw new IOException(String.format("An error ocurred trying to deserialize enum [%s]: ordinal %d is not a valid value.", type.getName(), ordinal), e);
            } finally {
                in.readRemainder();
        @SuppressWarnings({ "rawtypes" })
        @Override
        public void serialize(PofWriter out, Object obj) throws IOException {
             Enum e = (Enum) obj;
            out.writeInt(0, e.ordinal());
            out.writeRemainder(null);
    }Regards, Paul

  • PersistenceDelegate for typesafe enum pattern

    I've converted my code over from using int constants to the typesafe enum pattern in Effective Java. Unfortunately, the pattern only goes into serialization using Serializable and does not go into how to write a proper PersistenceDelegate that parallels the safety precautions of the Serializable enum. I've tried to do a direct mirroring of the readResolve() method given in the book inside of the intiatiate method of my PersistenceDelegate, but the XMLEncoder keeps rejecting the output and I get an InstantiationException, which shouldn't happen since the method call should not instantiate any new instances since the enums are static.
    class PositionBiasModePersistenceDelegate extends PersistenceDelegate {
        protected Expression instantiate(Object oldInstance, Encoder out) {
            PositionBiasMode mode = (PositionBiasMode) oldInstance;
            return new Expression(mode, PositionBiasMode.VALUES, "get", new Object[] {new Integer(PositionBiasMode.VALUES.indexOf(mode))});
    public abstract class PositionBiasMode {
        private final String name;
        private static int nextOrdinal = 0;
        private final int ordinal = nextOrdinal++;
        /** Creates a new instance of PreferredPositionMode */
        private PositionBiasMode(String name) {
            this.name = name;
        public String toString() {
            return name;
        public abstract boolean complies(PositionBias pb);
        public static final PositionBiasMode IGNORE = new PositionBiasMode("Ignore") {
            public boolean complies(PositionBias pb) {
                return true;
        public static final PositionBiasMode FRONT = new PositionBiasMode("Front") {
            public boolean complies(PositionBias pb) {
                return pb.hasBias() && pb.getPositionBias() < 0 ? false : true;
        public static final PositionBiasMode BACK = new PositionBiasMode("Back") {
            public boolean complies(PositionBias pb) {
                return pb.hasBias() && pb.getPositionBias() >= 0 ? false : true;
        private static final PositionBiasMode[] PRIVATE_VALUES = {IGNORE, FRONT, BACK};
        public static final List VALUES = Collections.unmodifiableList(Arrays.asList(PRIVATE_VALUES));
    }

    Yeah I tried this too. I think the instantiation exception is something to do with it trying to recreate the MyEnum.VALUES List. I don't understand enough about the process to know how to fix that though.
    The approach I eventually went for was to add a couple of things to the enum class as follows:
    // add to MyEnum class:
    public static final PersistenceDelegate PERSISTENCE = new PersistenceDelegate()
         protected boolean mutatesTo(Object oldInstance, Object newInstance)
              return (MyEnum)oldInstance == (MyEnum)newInstance;
         protected Expression instantiate(Object oldInstance, Encoder out)
              MyEnum enum = (MyEnum)oldInstance;
              return new Expression(enum, new MyEnum.Factory(), "forOrdinal", new Object[]{new Integer(enum.ordinal)});
    public static final class Factory
         public MyEnum forOrdinal(int ordinal)
              return PRIVATE_VALUES[ordinal];
    // usage:
    XMLEncoder enc = new XMLEncoder(...);
    enc.setPersistenceDelegate(MyEnum.class, MyEnum.PERSISTENCE);Not entirely sure it's the ideal approach but maybe it'll work for you. Cheers.

  • Enum and Interfaces

    Hi,
    currently I am using a generic parameter like
    public class SomeClass<C extends Enum<C>>meaning that I have a generic type parameter that is guaranteed to be an enum. But this is not enough. I would like to require that any instantiation of C also implements a certain interface. In principle I would like to write
    public class SomeClass<C extends Enum<C> implements SomeInterface>which is of course not the correct syntax.
    Is there a way to express what I want in Java?
    Thanks,
    Harald.
    Edited by: pifpafpuf on 28.12.2009 22:19
    Edited by: pifpafpuf on 28.12.2009 22:19

    Peter__Lawrey wrote:
    There are some examples in the collections libraries. Can't remember where now.example in collections API: [<T extends Object & Comparable <? super T>> T max(Collection<? extends T> coll)|http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html#max(java.util.Collection)|extends Object & Comparable]

  • Enum vs static final String

    I was going to use static final Strings as enumerated constants in my application, but would like to see if I should be using enums instead.
    In terms of efficiency, if I have, say, 5 enumerated elements, will only one copy of the enumerated element be in memory, like a static final String? So regardless of how many times I refer to it, all references point to the same instance (I'm not sure if what I just said even makes sense in the context of enums, but perhaps you could clarify).
    Are there any reasons why for enumerated constants that are known at development time, why static final Strings (or static final anything, for that matter) should be used instead of enums if you're using JDK 1.5?
    Thanks.

    In terms of efficiency, if I have, say, 5 enumerated elements, will only one copy of
    the enumerated element be in memory, like a static final String?I don't know if it addesses your concerns, but the the Java Language Specification says this about enums: "It is a compile-time error to attempt to explicitly instantiate an enum type (�15.9.1). The final clone method in Enum ensures that enum constants can never be cloned, and the special treatment by the serialization mechanism ensures that duplicate instances are never created as a result of deserialization. Reflective instantiation of enum types is prohibited. Together, these four things ensure that no instances of an enum type exist beyond those defined by the enum constants." (http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.9)
    As for the problems of memory usage, how big are these strings anyway?
    The advantages of using enums over static final strings are discussed in the "technotes" accompanying 1.5 http://java.sun.com/javase/6/docs/technotes/guides/language/enums.html They list the following as problems with the static final "antipattern"
      * It is not typesafe (methods that expect one of your constants can be sent any old string)
      * There is no name space - so you must continually be sure that your constants don't have names that may be confused
      * Brittleness. Your strings will be compiled into the clients that use them. Then later you add a new constant...
    �  * Printed values will be uninformative. Perhaps less of a problem for Strings, but, still, simply printing the string will leave its semantic significance obscure.

  • APEX application or page url  - How to use enum string to replace ID number

    URL to a APEX page is format as ***/f?p=APPLICATION_ID:PAGE_ID:... . Here the APPLIACTION_ID and PAGE_ID are numbers.
    My Question is: Is there a way to replace the numbers by using strings? For example: can I have a URL like /f?p=MY_APPLICATION:MY_PAGE1: ... ? Juts like ENUM in other languages, MY_APPLICATION actually just represent the application id but much more readable since it is a string with a name the user may familar.
    Please help.
    Thank you.

    You can assign an alphanumeric alias to applications and pages using their respective attribute edit forms in the Application Builder. Then you can construct links that use those aliases instead of the IDs. These aliases will generally be preserved in the URL visible in the browser, but not in all cases. You have to deliberately use the aliases in any branch definitions, list item targets, etc. Note that application aliases must be unique within a workspace. Please see the User's Guide for more info.
    Scott

  • Why "null" value is impossible in "switch(val) {case null: }"  for enums?

    I'm wondering why Java 5.0 does not allow null values
    as options in switch statement:
    If type E is "enum" then the following language construction is
    not allowed:
    E val;
    switch(val) {
       case A:
         break;
       case B:
           break;
       case null:   // this is not allowed
            break;
    }Can somebody explain me why Java does not support it? I beleave that
    some serious reasons were for that.
    As we know enum types can have "null" values and in case I use nulls
    for my enumerations the code with "switch" statement becomes quite urgly because it is necessary to handle 2 separate execution paths:
    null and not null.
    Thanks

    I really don�t know too much about 1.5, but I can tell you that for 1.4 the switch receives as a parameter an int or anything that can be casted automatically to an int. Therefore you can�t never use null cause int, char, short, byte can�t never take as a value null.

  • How to get I32 enum text out of a control (i/p terminal config, active edge of DAQmx vis)

    Hi,
     I am using DAQmx VIs create channel.vi and sample clock.vi, they have inputs (input terminal configuration) and (active edge) both are I32 and have enum looking drop down options. i want to use those text values to put into my excel file, but they give out numeric codes related to respective option. is it possible to get the text as it is.
    it is not an enum but I32 which looks like enum..
    plz help..
    Thanks
    Solved!
    Go to Solution.

    Note: This assumes that you have an actual control on the VI. If you have a
    block diagram constant, then that won't actually work. In this case to get the actual text you need to pick from list of text items. To further complicate things, the actual values that are generated are not sequential. You can use either a case structure or a 2-step lookup.
    Attachments:
    Example_VI.png ‏7 KB

  • Using static .values() method of Enum in Generic Class

    Hi *,
    I tried to do the following:
    public class AClass<E extends Enum<E> >  {
         public AClass() {
              E[] values = E.values(); // this DOESN'T work
              for (E e : values) { /* do something */ }
    }This is not possible. But how can I access all Enum constants if I use
    an Enum type parameter in a Generic class?
    Thanks for your help ;-) Stephan

    Here's a possible workaround. The generic class isn't adding much in this case; I originally wrote it as a static method that you simply passed the class to:
    public class Test21
      public static enum TestEnum { A, B, C };
      public static class AClass<E extends Enum<E>>
        private Class<E> clazz;
        public AClass(Class<E> _clazz)
        {  clazz = _clazz;  }
        public Class<E> getClazz()
        {  return clazz;  }
        public void printConstants()
          for (E e : clazz.getEnumConstants())
            System.out.println(e.toString());
      public static void main(String[] argv)
        AClass<TestEnum> a = new AClass<TestEnum>(TestEnum.class);
        a.printConstants();
    }

  • Session scope managed bean is not instantiating?

    We have the need to use a session bean (rather than pageFlowScope) in our application.  But it looks like the session beans are not being instantiated at run time like other beans are.  I created a simple test case to verify.  One bean, named "MySessionBean", defined in the task flow as Session scope, then referenced in a view with an input text box, value:  #{sessionScope.MySessionBean.value1}. When I run the application,  I just get PropertyNotFoundException, Target Unreachable, 'MySessionBean' returned null.
    If I simply change the bean to use pageFlowScope, everything works fine.   I have debug code in the bean constructor, and it never gets called.   Is there some other step I am missing to have ADF instantiate the session bean?

    No luck, I tried it in both adfc-config.xml, and faces-config.xml.  I also tried moving the call to my view, from my bounded taskflow, into the adfc-config unbounded task flow, and then I ran that instead.  Still got the same error.    Here is my code from the the last round of tests with the view called in the main adfc-config.xml unbounded taskflow:
    adfc-config.xml:
    <?xml version="1.0" encoding="windows-1252" ?>
    <adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2">
          <view id="testView">
                <page>/testView.jspx</page>
          </view>
          <managed-bean id="__2">
          <managed-bean-name id="__5">MySessionBean</managed-bean-name>
          <managed-bean-class id="__4">test.MySessionBean</managed-bean-class>
          <managed-bean-scope id="__3">session</managed-bean-scope>
        </managed-bean>
    </adfc-config>
    testView.jspx:
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
      <jsp:directive.page contentType="text/html;charset=UTF-8"/>
      <f:view>
        <af:document id="d1">
          <af:form id="f1">
            <af:inputText label="Label 1" id="it1"
                          value="#{sessionScope.MySessionBean.value1}"/>
          </af:form>
        </af:document>
      </f:view>
    </jsp:root>
    MySessionBean.java:
    package test;
    public class MySessionBean {
        private String value1="Hello World";
        public MySessionBean() {
            super();
        public void setValue1(String value1) {
            this.value1 = value1;
        public String getValue1() {
            return value1;

  • Instantiation of new objects - a beginners cry for help!!!

    Hi - i am working through (on no not another bloody Bank Account) problem. It is the same problem posted in this topic - http://forum.java.sun.com/thread.jsp?forum=31&thread=308754
    where the author was roundly slated for not even having a go.
    I am not asking for someone to complete the program but would like to be kicked off again having ground to a halt.
    I had decided to create a Parent Bank Account class and then create child classes for Current, Platinum and Student Accounts. I am very unsure as to how to then create the methods that will allow the user to, for instance, check the balance, deposit an amount etc. While I am generally comfortable with While/Do's and Else/If's, Im still very rusty with the terminology and instantiation of objects that users can manipulate (having never yet created a working program!).
    Please read what I've done so far and then I would be msot grateful for pointers. Or if you want to slate me then at least make it funny!
    public class bankAccount { //Declares superclass
    private String name; //Account Holder Name
    private int accNo; //Account Number
    private String accType; //Type of Account
    private int balance; //Balance
    private int deposit; //Depost
    private int withdrawal; //Withdrawal
    private boolean overdrawn; // Overdrawn or in Credit?
    public bankAccount() {} // Default constructor
    public bankAccount(String n, int a) { //Constructor #1
    name = n;
    accNo = a;
    deposit = false;
    withdrawal = false;
    public bankAccount(String n, int a, boolean d, boolean w) {//Constructor #2
    name = n;
    AccNo = a;
    deposit = d;
    withdrawal = w;
    public String getName() { //get() and set () methods
    return name;
    public void setName(String n){
    name = n;
    public int getAccNo(){
    return accNo;
    public void setAccNo(int accNo){
    accNo = a;
    public String getAccType(){
    return accType;
    public void setAccType(String at){
    accType = at}
    public int getBalance(){
    return balance;
    public void setBalance(int b){
    balance = b;
    public int getDeposit(){
    return deposit;
    public void setDeposit(int d){
    deposit = d;
    public int getWithdrawal(){
    return withdrawal;
    public void setWithdrawal(int w){
    withdrawal = w;
    public boolean getOverdrawn(){
    return overdrawn;
    public void setOverdrawn(boolean o){
    overdrawn = o;
    public void printOut(){
    System.out.println (name + accNo + accType + balance + deposit + withdrawal+
    overdrawn);
    } //end of bankAccount class
    public class Current extends BankAccount {//Current Account class derived from Bank Account class
    public current () {} //empty method for default constructor
    public current (String n, int a, boolean a, boolean w){
    setname(n);
    setaccNo(a);
    set deposit(false);
    set withdrawal(false); //this is as far as I got before punching the computer!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    You've gotta give him credit though, he did try. apparently didn't work, must be caps sensitive.
    And Barty1... remember to close your code brackets, otherwise it tends to chop off the last 2 lines or so.
    Cheers,
    Radish21                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Sun's demo using enum doesn't seem to work for me

    I'm trying to run a demo from the Sun website, http://java.sun.com/docs/books/tutorial/java/nutsandbolts/switch.html, which includes the enum statement:
    public class SwitchEnumDemo {
        public enum Month { JANUARY, FEBRUARY, MARCH, APRIL,
                            MAY, JUNE, JULY, AUGUST, SEPTEMBER,
                            OCTOBER, NOVEMBER, DECEMBER }
        public static void main(String[] args) {
            Month month = Month.FEBRUARY;
            int year = 2000;
            int numDays = 0;
            switch (month) {
                case JANUARY:
                    // etc etc ...
            System.out.println("Number of Days = " + numDays);
    }However, copying-and-pasting the code into NetBeans, I get an error on the enum declaration stating: '';' expected. Warning: as of release 1.5, 'enum' is a keyword and may not be used as an identifier'. Well... I know that. Isn't that why I'm using it in the first place? Or am I confused?
    I'm using NeBeans 5.0 on Java 1.5.0_06.
    Any advice?
    Question 2: Once I get this thing working, is there any way I can get the month as an input from the user, without needing a long block stating
    if (input = "January") month = Month.JANUARY;
    else if (input = "Feburary") month = Month.FEBURARY;
      //etc etcThat is, can the string representation of a month be somehow kept within the enumerated Month itself, and that be used to check the user's input?
    Thanks for any advice!

    However, copying-and-pasting the code into NetBeans,
    I get an error on the enum declaration stating:
    '';' expected. Warning: as of release 1.5, 'enum'
    is a keyword and may not be used as an
    identifier'. Well... I know that. Isn't
    that why I'm using it in the first place? Or am I
    confused?
    I'm using NeBeans 5.0 on Java 1.5.0_06.I can't say for sure about that; it seems very odd. However, I do know that my IDE will warn me about those sorts of things if I configure my project for pre-1.5 operation. It allows me to say a project is for Java 1.4 even if I'm using a 1.5 JVM and will mention things like that so that forward compatibility can be considered. I don't suppose this could be the case with your situation?
    You might want to search for all instances of "enum" in your code, though, because it's hard to imagine the one instance which appears in the snippet you posted causing problems.
    Question 2: Once I get this thing working, is there
    any way I can get the month as an input from the
    user, without needing a long block stating{snip}
    Well, in this case you can just do
    for (Month m : Month.values())
        if (m.toString().equalsIgnoreCase(input))
            month = m;
            break;
    }or you can build a Map<String,Month> if you're looking for case-sensitive comparison.
    In general, however, you can put pretty much anything into an enum:
    public enum SomeEnum
        A(0),
        B(0),
        C(1),
        D(0),
        E(2);
        private int value;
        SomeEnum(int value)
            this.value = value;
        public int getValue()
            return value;
    // the following is perfectly legal
    SomeEnum e = methodThatReturnsSomeEnum();
    System.out.println(e.getValue());and you could use that to put some form of identifier in the enumeration object. I have a class around here somewhere which uses an enum to enumerate the operators in an expression parser; the Operator enum constructor accepts an int specifying the operator precedence.

  • Importing  Through DTW : "Invalid ItemName'M'  in Enum 'BO Gender Types

    Dear Members,
    I am trying to import in a Business Partner,the contact person in which the gender and date of birth is to be imported.?its showing an error named "Invalid Item Name'M'  in Enum 'BO Gender Types 65171.
    Can anyone help me in this regard to import through template.
    Thanks ,
    Venkatesh.R

    Hi sudha,
    Thanks a lot,one of my issues has been solved,can you tell me how to import similarly for date of birth.
    Regards,
    Venkatesh.R

Maybe you are looking for

  • How to get ServletContext from HttpServletRequest when there is no session?

    Does anyone know of a way to be able to pull the ServletContext from an HttpServletRequest if there is not a session available?

  • DBIF_SETG_SQL_ERROR - after Upgrade to 10.2.0.2

    After Upgrade from Oracle 9.2.0.7 to Oracle 10.2.0.2 i have the Problem that the User: <SID>adm cannot use brtools for example brsapce to extend a tablespace exec(): 0509-036 Cannot load program /usr/sap/NT1/SYS/exe/run/brspace because of the followi

  • BAPI_SALESORDER_CHANGE [delete line item and update ]

    LOOP AT itab_ch .   *IF itab_ch-itm_number = selpos1 AND  delflag = 'X'.* *     Delete Line items     s_order_header_inx-updateflag = 'U'.     i_order_item_in-itm_number = itab_ch-itm_number.    schedule_lines-itm_number = itab_ch-itm_number.     sch

  • Can't install FC on new MacPro - invalid serial number

    I just got my new MacPro and had done the crossgrade to get the universal FCS. I used the sound track pro upgrade to crossgrade to FCS. I went to install and I can't seem to figure out what the valid serial number is. The serial number from my prior

  • HT1338 i want to change my Apple ID

    i want to change my Apple ID because i left the job, but my id is official but the payment is made by me so i need the software    so the id has to be changed from one to another please help me