[英]can we store method passing argument in java variable
how can i store this displayPriceMessage method with argumetnt in variable 我如何将这个argumetnt的displayPriceMessage方法存储在变量中
//method of displayPriceMethod
public void displayPriceMessage(String name, String msg, boolean cream, boolean coke)
{
priceamoutntxt.setText("\n Name: "+Ename.getText().toString()+"\n total : "+priceamoutntxt.getText()+"\n Add Ice-Cream ?"+ cream +"\n Add Coca-Cola ?"+coke+"\n than you ");
}
// displayPriceMessage argumetnt
displayPriceMessage("ename","",isIceCream, cocaCola);
You can do this in FP. 您可以在FP中执行此操作。 Perhaps you would need a custom Functional Interface. 也许您需要一个自定义的功能接口。
DisplayPriceMessage displayPriceMessage = this::displayPriceMessage;
public void displayPriceMessage(String name, String msg, boolean cream, boolean coke)
{
priceamoutntxt.setText("\n Name: "+Ename.getText().toString()+"\n total : "+priceamoutntxt.getText()+"\n Add Ice-Cream ?"+ cream +"\n Add Coca-Cola ?"+coke+"\n than you ");
}
Create a functional interface having an abstract method of similar signature as that of displayPriceMessage 创建一个功能接口,该接口具有与displayPriceMessage相似的签名的抽象方法
@FunctionalInterface
interface DisplayPriceMessage {
void displayPriceMessage(String name, String msg, boolean cream, boolean coke);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.