繁体   English   中英

我们可以在Java变量中存储传递参数的方法吗

[英]can we store method passing argument in java 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);

您可以在FP中执行此操作。 也许您需要一个自定义的功能接口。

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 ");
}

创建一个功能接口,该接口具有与displayPriceMessage相似的签名的抽象方法

@FunctionalInterface
interface DisplayPriceMessage {
    void displayPriceMessage(String name, String msg, boolean cream, boolean coke);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM