简体   繁体   English

边界不匹配:类型A不是边界参数的有效替代品 <T extends Entity> 类型为TestService <T>

[英]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.

相关问题 绑定不匹配:MyClass1类型不是绑定参数的有效替代品 <T extends Comparator<T> &gt;类型的人 <T> - Bound mismatch: The type MyClass1 is not a valid substitute for the bounded parameter <T extends Comparator<T>> of the type Person<T> 为什么“类型绑定不匹配:类型? 扩展T不是有界参数的有效替代品 <E extends Enum<E> &gt;枚举类型 <E> “? - Why ”Type Bound mismatch: The type ? extends T is not a valid substitute for the bounded parameter <E extends Enum<E>> of the type Enum<E>“? 绑定不匹配:该类型不是绑定参数的有效替代 - Bound mismatch: The type is not a valid substitute for the bounded parameter 有界不匹配:类型不是有界参数的有效替代品<e extends comparable<e> &gt; 类型</e> - Bound mismatch: The type is not a valid substitute for the bounded parameter <E extends Comparable<E>> of the type Java Generics - 绑定不匹配:类型 Object 不是绑定参数的有效替代品<e extends comparable<e> &gt;</e> - Java Generics - Bound mismatch: The type Object is not a valid substitute for the bounded parameter <E extends Comparable<E>> Java泛型:绑定不匹配:类型不是该类型的bounded参数的有效替代 - Java generics: Bound mismatch: The type is not a valid substitute for the bounded parameter of the type Java泛型,绑定不匹配:类型不是bounded参数的有效替代品 - Java generics , bound mismatch: The type is not a valid substitute for the bounded parameter Java泛型绑定不匹配:类型不是边界参数的有效替代品 - java generics Bound mismatch: The type is not a valid substitute for the bounded parameter 类型 T 不是有界参数的有效替代品 ` <t extends collection<?> &gt;</t> - Type T is not a valide Substitute for the bounded Parameter `<T extends Collection<?>> Eclipse中有限的不匹配。 “该类型不是有界参数的有效替代” - Bounded mismatch in Eclipse. “The type is not a valid substitute for the bounded parameter”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM