i was thinking along the line when design some interfaces and classes whether i should be passing enum as a parameter or its literal value.
At this juncture, i am all for passing its literal value as i have read somewhere i could not remember about coupling issues passing the enum.
Does anyone have any opinion on this? 🙂
public enum Item{
CANDY("candy"), APPLE("apple");
}
-
Pass by enum
public buy(Item item){} -
Pass by literal value
public buy(String itemValue){}
Cheers.
Enums are classes but with a set of predefined values. As such you must both declare the enum and give a variable for its instance.
Try this example :