它 不能同时 实现。
为此,它需要在使用泛型的接口中实现每种方法的两个版本。让我们举一个例子:
bindBidirectional(Property<Long> other) { ... }在幕后,擦除意味着可以简化为:
bindBidirectional(Property other) { ... }那么,什么将实现
Property<Number>并
Property<Long>做什么呢?它有两种方法:
bindBidirectional(Property<Long> other) { ... }bindBidirectional(Property<Number> other) { ... }…在擦除后将编译为两种方法:
bindBidirectional(Property other) { ... }bindBidirectional(Property other) { ... }这两种方法相互冲突,并且无法在运行时解决它们。
即使您使用了一些编译器技巧来解决此问题,当有人将LongProperty用作原始Property时会发生什么?
Property rawLongProperty = new LongProperty();rawLongProperty.bindBidirectional(someOtherRawProperty);
无法知道
bindDirectional要解决的两个变体中的哪个。



