gpt4 book ai didi

java - 自动装箱和原始类型以匹配方法签名

转载 作者:行者123 更新时间:2023-12-01 07:26:01 26 4
gpt4 key购买 nike

1.5版本中,Java引入了自动装箱的概念。

public interface SomeInterface {
public void test(Integer val);
}

public class Main implements SomeInterface {

/*The method signature gets different and compiler is asking to override
un-implemented methods*/
public void test(int t) {

}
}

那么为什么我在覆盖未实现的方法时遇到编译时错误,为什么上面的测试方法的参数没有自动装箱以匹配父测试方法签名?

最佳答案

因为子类is not override-equivalent中的方法与 super 类的一位。父类(super class)方法可以采用 null 作为参数,而子类方法则不能(这里没有关于自动装箱的内容)。

关于java - 自动装箱和原始类型以匹配方法签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24549716/

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