奇怪的绑定mismtatch使用泛型

时间:2015-08-15 23:07:47

标签: java generics

我有:

public abstract class HistorizableStatusEntity<S extends Status, 
       O extends IdentifiedEntity> extends IdentifiedEntity

具体实施:

public class OrderStatusHistory extends HistorizableStatusEntity<OrderStatus, Order>

现在有:

public abstract class StatusableEntity<H extends HistorizableStatusEntity<S, IdentifiedEntity>, 
       S extends Status> extends IdentifiedEntity

具体实施:

public class Order extends StatusableEntity<OrderStatusHistory, OrderStatus>

java编译器说Order

Bound mismatch: The type OrderStatusHistory is not a valid substitute for the bounded parameter <H extends HistorizableStatusEntity<S,IdentifiedEntity>> of the type StatusableEntity<H,S>

我不明白这一点,因为 OrderStatusHistory 扩展了HistorizableStatusEntity<S,IdentifiedEntity>>

有什么想法吗? TIA!

1 个答案:

答案 0 :(得分:2)

StatusableEntity期望类型为H extends HistorizableStatusEntity<S, IdentifiedEntity>,而您提供的OrderStatusHistory会扩展为HistorizableStatusEntity<OrderStatus, Order>。如您所见,正确的类型与StatusableEntity期望的内容不匹配(OrderIdentifiedIdentity不匹配)。