没有Lambda,谓词,接口。只是带有常规吸气剂的常规班。例如:
public int getWeight(){return weight;}
public int convertToLbs(int weight){some code here ...}
someObject.convertToLbs(someObject.getWeight())//valid???
谢谢
答案 0 :(得分:2)
您当前的语法有效,但是您正在传递weight
值,因为Java is pass-by-value。
要为返回int
的内容传递方法引用,可以使用IntSupplier
:
public int getWeight() { return weight; }
public int convertToLbs(IntSupplier s) { int w = s.getAsInt(); ... }
someObject.convertToLbs(someObject::getWeight);