java implement 泛型_使用List参数实现泛型方法(Implement generic method with List parameter)...

博主在尝试定义并实现一个接受Object列表作为参数的抽象setter方法时遇到问题。Java编译器报错指出该方法并未重写超类方法,因为两个方法的擦除相同。博主对擦除错误有所理解,但不清楚如何正确实现。尝试了不同的签名,但未能找到解决方案。博客中提到已查阅教程和StackOverflow上的相关问题,但没有找到明确答案。
摘要由CSDN通过智能技术生成

I'm trying to define and then implement an abstract setter which takes a List of Objects as a parameter. Here's the gist of this simple idea:

public abstract class MyClass {

public abstract void setThings(List> things);

}

public class Bar extends MyClass {

private List things;

@Override

public void setThings(List things) {

this.things = things;

}

}

That doesn't work. I get Method does not override method from its superclass and both methods have the same erasure, but neither overrides the other. I understand the latter error relating to erasures, but even so I can't figure out the correct way to do this. I've tried some others like:

public abstract void setThings(List things);

...as well as a few others. And I've found other questions/answers on SO that come close to addressing this, but none that have provided a solid answer (at least not that was clear to me). I've read through the tutorials as well to no avail. What am I missing?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值