2

enum Class がPropertyあり、プログラムの一部で、StringまたはのSerializable値を置き換えたいと考えていPropertyます。どうやってやるの?

public enum Property {
    Autofocus,
    Bluetooth,
    Brand,...}

値またはをProperty使用して値を割り当てるにはどうすればよいですか:SerializableString

Property property;
this.property = (Serializable) value;

また

this.property = "value";

それ以外の

this.property = Property.Autofocus;
this.property = Property.Brand; // ...
4

3 に答える 3

2

使用java.lang.Enum.valueOf(Class<T> enumType, String name):

Property p = Enum.valueOf(Property.class, "Autofocus");
System.out.println(p);
于 2013-09-12T13:32:18.047 に答える
1
Property.valueOf("Bluetooth");

それがあなたが意図したものであれば、文字列から列挙型の値までの値を取ります

静的メソッドvalueOf()values()はコンパイル時に作成され、ソース コードには表示されません。ただし、Javadoc には表示されます。たとえば、Dialog.ModalityType両方の方法を示します。

于 2013-09-12T13:34:30.973 に答える