gpt4 book ai didi

Java 8 - Wildcard extends with BiPredicate 不工作

转载 作者:行者123 更新时间:2023-11-29 04:14:05 25 4
gpt4 key购买 nike

<分区>

我不知道为什么它不起作用。

eclipse 中的错误信息:BiPredicate 类型中的方法 test(Fruit, capture#1-of ? extends Fruit) 不适用于参数 (Fruit, Mango)

import java.util.function.BiPredicate;

public class PredTest {

public static void main(String[] args) {

class Fruit {
public String name;
public String color;
Fruit(String name) {this.name = name; }
};

class Apple extends Fruit {
Apple() {super("Apple");}
};
class Mango extends Fruit {
Mango() {super("Mango");}
};

BiPredicate<Fruit, ? extends Fruit> tester = (f, nf) -> {
System.out.println(nf.name);
return true;
};
Fruit f = new Fruit("Not named");
Apple a = new Apple();
Mango m = new Mango();

// ########### I see error in the below line
System.out.println(tester.test(f, m));

}

}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com