I have trying to create an object based on the type
using switch statement. However I am getting this error on the method in main method:
Cannot make a static reference to the non-static method CreateCoffee(CoffeeFactory.Type) from the type CoffeeFactory
public Coffee CreateCoffee(Type t ) {
ingred = null;
switch (t) {
case LONG_BLACK:
ingred.add(Ingredient.ESPRESSO);
return new Coffee(ingred, t);
case FLAT_WHITE:
ingred.add(Ingredient.MILK);
return new Coffee(ingred, t);
case MOCHA:
ingred.add(Ingredient.CHOCOLATE);
return new Coffee(ingred, t);
default: return null;
}
}
public static void main(String[] args) {
CreateCoffee(Type.MOCHA);
}
what am i doing wrong, is it the return new Coffee()
statement in each switch case?