gpt4 book ai didi

java - Java 泛型中的困惑

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

我是Java初学者,我正在尝试编译一些小程序,有人可以解释一下,我的问题是什么,提前感谢:

public abstract class SumFunction<Y,X> {
public abstract Y op (Y y, X x);
}

public class sumStringToInt extends SumFunction{
public int op(int num, String s){
return s.length() + num;
}
}

错误

Multiple markers at this line
- The type sumStringToInt must implement the inherited abstract method SumFunction.op(Object,
Object)
- SumFunction is a raw type. References to generic type SumFunction<Y,X> should be
parameterized

已编辑

Java中是否可以在不实例化基类的情况下继承?,提前感谢

最佳答案

您表示SumFunction<Y,X>有两个参数。

因此你的类应该如下所示:

public class sumStringToInt extends SumFunction<Integer,String> {
public Integer op(Integer num, String s){
return s.length() + num;
}
}

尝试一下...

关于java - Java 泛型中的困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4094934/

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