Re: Smuggling information to enums
Roedy Green wrote:
What the techniques are there for smuggling information to enums?
they don't have constructors.
Answered by others.
It is not clear how you would make them nested classes.
public class Foo
{
enum Bar { PLUGH, XYZZY, SHAZAM }
...
}
Is it possible to somehow have two enum class objects in RAM at once,
each with different instance data?
An enum can only have as many instances as it has enum values. Each
of those instances can have different instance data, e.g. (untried,
untested, uncompiled),
public enum Suit
{
CLUBS( CLUB_IMAGE ), DIAMONDS( DIAMOND_IMAGE ),
HEARTS( HEART_IMAGE), SPADES( SPADE_IMAGE );
private Image aceImage;
Suit( Image image )
{ this.aceImage = image; }
public Image getAceImage()
{ return this.aceImage; }
public void setAceImage( Image image )
{ this.aceImage = image; }
}
Do you have to pass it in each time with the method or use static
setters?
Instance setters.
--
Lew