我如何存储带有变量的参数的显示价格消息方法

最佳答案

您可以在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);
}

10-07 16:08