Mic*_*ael 4 java generics java-8 functional-interface
当属于变量的方法的引用被破坏时会发生什么?
public class Hey{
public double bar;
public Hey(){
bar = 2.0d;
}
public double square(double num){
return Math.pow(num , bar);
}
}
Function<Double, Double> square;
whatsGonnaHappen: {
Hey hey = new Hey();
square = hey::square;
}//is hey still kept around because its method is being referenced?
double ans = square.apply(23d);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
191 次 |
| 最近记录: |