在方法(java)中传递值作为参数
Passing value in method(java) as an argument
我创建了一个枚举
public enum Fruit {
mango , banana , apple , guava;
}
我有一个函数,我想在其中将枚举作为参数传递并使用该参数。
功能是这样的
getFruits(Fruit.apple) // calling function
public void getFruit( **What to write here to use that Fruit enum**) {
double sweetValue = sweetValueOfFruit( **how can i pass Fruit.apple here**)
}
假设 sweetValue 函数在某处定义。
请帮我写代码(对于** **之间的所有代码)。
谢谢,社区 :)
Fruit 是枚举,所以使用与 class
相同的方式创建它的对象
public void getFruits( Fruit aFruit) {
double sweetValue = sweetValueOfFruit( aFruit);
}
建议命名约定使所有枚举都为大写字母
原来如此
public enum Fruit {
MANGO , BANANA , APPLE , GUAVA;
}
我创建了一个枚举
public enum Fruit {
mango , banana , apple , guava;
}
我有一个函数,我想在其中将枚举作为参数传递并使用该参数。 功能是这样的
getFruits(Fruit.apple) // calling function
public void getFruit( **What to write here to use that Fruit enum**) {
double sweetValue = sweetValueOfFruit( **how can i pass Fruit.apple here**)
}
假设 sweetValue 函数在某处定义。
请帮我写代码(对于** **之间的所有代码)。 谢谢,社区 :)
Fruit 是枚举,所以使用与 class
相同的方式创建它的对象public void getFruits( Fruit aFruit) {
double sweetValue = sweetValueOfFruit( aFruit);
}
建议命名约定使所有枚举都为大写字母
原来如此
public enum Fruit {
MANGO , BANANA , APPLE , GUAVA;
}