Generics in enums (original) (raw)
Victor Polischuk victor2 at ukr.net
Wed May 29 07:51:45 UTC 2013
- Previous message: hg: jdk8/tl/jdk: 8015440: java/lang/management/MemoryMXBean/ResetPeakMemoryUsage.java fails with RuntimeException
- Next message: Fw: Generics in enums
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Greetings,
Some time ago I wanted to migrate our "commons-lang" enums to "java 5" enumerations, but I encountered an issue that it cannot be done without discarding generics since java enums do not support them. Let me show an example:
//------
public final class ColorEnum extends org.apache.commons.lang.enums.Enum { public static final ColorEnum RED = new ColorEnum("Red"); public static final ColorEnum GREEN = new ColorEnum("Green"); public static final ColorEnum BLUE = new ColorEnum("Blue"); public static final ColorEnum WHITE = new ColorEnum("White") {
@Override
public MixedPixel make() {...}
};
private ColorEnum(String color) {super(color);}
public boolean filter(T pixel) {...}
public T make() {...} }
//------
And I wonder if there is a specific reason why I cannot convert it into something like:
//------
public enum Color { RED("Red"), GREEN("Green"),
BLUE ("Blue"),
WHITE("White") {
@Override
public MixedPixel make() {...}
};
private Color(String color) {...}
public boolean filter(T pixel) {...}
public T make() {...} }
//------
Thank you in advance.
Sincerely yours,
Victor Polischuk
- Previous message: hg: jdk8/tl/jdk: 8015440: java/lang/management/MemoryMXBean/ResetPeakMemoryUsage.java fails with RuntimeException
- Next message: Fw: Generics in enums
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]