<分区>
为什么代码:
Hello hello = GreetingUtil.hello();
收到此错误?
Incompatible types
Required Hello
Found Greeting
假设这些是类/接口(interface),我无法控制 Greeting
和 HelloWorld
,因为它们是外部 API,不是 Hello
是问候语
类型的吗?
public interface Greeting {
}
public interface Hello extends Greeting {
}
public class HelloWorld implements Greeting {
}
public class GreetingUtil {
public static Greeting hello() {
return new HelloWorld();
}
}
或者,我理解错了吗?谢谢。