enum icecream { vanilla(100), strawberry(20); int price; icecream(int i) { price = i; } }
I'm a little confused about how enumeration objects are created at compile time
I saw some examples where they referred to this as
public enum Flavor { COFFEE, VANILLA, CHOCOLATE, STRAWBERRY, RUM_RAISIN, PEACH }
This will convert (at compile time)
public final class Flavor extends java.lang.Enum { public static final Flavor COFFEE = new Flavor("COFFEE", 0); public static final Flavor VANILLA = new Flavor("VANILLA", 1);
Link: http://www.kdgregory.com/index.php?page=java.enum
But how objects are created when I pass the value along with the name, it seems to me that they just look like method calls. Ex vanilla (100) here for vanilla price is 100, but how is it really created? I do not get it at all. Please, help: (
source share