[英]Bound mismatch: The type A is not a valid substitute for the bounded parameter <T extends Entity> of the type TestService<T>
Im getting this exception when compiling MyService. 我在编译MyService时遇到此异常。 What is the issue in the generics definition here?
这里的泛型定义有什么问题?
public interface Entity extends Serializable{
public <T extends Serializable> T getId();
}
public class A implements Entity {
... some code
}
public abstract class TestService<T extends Entity> implements Serializable {
...some code
}
public class MyService extends TestService<A> {
...some code
}
The error simply tells that the type parameter T you are using here public abstract class TestService<T extends Entity> implements Serializable {
is a bound parameter extending Entity
. 该错误仅表明您在此处使用的类型参数T
public abstract class TestService<T extends Entity> implements Serializable {
是扩展Entity
的绑定参数。
Whereas, here public class MyService extends TestService<A> {
, you are specifying an unbound parameter A . 而在这里,
public class MyService extends TestService<A> {
,您将指定一个未绑定的参数A。
I am not sure whether it has to do anything with the Java version 5 onwards, you can refer this Type Erasure 我不确定从Java版本5开始是否需要执行任何操作,您可以参考此Type Erasure
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.