interface New<T> {
boolean func(T n, T v);
}
class MyFunc<T>{
T val;
MyFunc(T val){
this.val = val;
}
void Set(T val){
this.val = val;
}
T Get(){
return val;
}
boolean isEqual(MyFunc<T> o){
if(val == o.val) return true;
return false;
}
public class Main {
static <T> boolean check(New<T> n , T a, T b){
return n.func(a,b);
}
public static void main(String args[]){
int a = 321;
MyFunc<Integer> f1 = new MyFunc<Integer>(a);
MyFunc<Integer> f2 = new MyFunc<Integer>(a);
boolean result;
//f2.Set(f1.Get()); //if i uncomment this line result become true
System.out.println(f1.val + " " + f2.val);
System.out.println();
result = check(MyFunc::isEqual, f1, f2);
System.out.println("f1 isEqual to f2: " + result);
}
}
为什么在and'a'
中使用时结果为假?为什么未注释时结果为真?请解释我在哪里犯了错误。f1
f2
f2.Set(f1.Get());