Ненависти к жабе псто
Sep. 22nd, 2011 10:28 pmА вы знаете, почему разные авторы диаметрально противоположно описывают маски с ограничением super? Например, в разных изданиях Хорстманн описывает разное поведение подстановочных типов с ограничением на супертипы.
For example, Pair<? super Manager> has methods
void setFirst(? super Manager)
? super Manager getFirst()
The compiler doesn’t know the exact type of the setFirst method but can call it with any object of type Manager, Employee, or Object, but not a subtype such as Executive.
Это противоречит его более раннему изданию, где в setFirst можно передавать Manager и Executive, но не их супертипы.
Одновременно у Эккеля аналогичная цитата:
the argument is now a List<? super T>, so the List holds a specific type that is derived from T; thus it is safe to pass a T or anything derived from T as an argument to List methods.
Впрочем, эксперимент подтверждает правоту Эккеля:
( Read more... )
For example, Pair<? super Manager> has methods
void setFirst(? super Manager)
? super Manager getFirst()
The compiler doesn’t know the exact type of the setFirst method but can call it with any object of type Manager, Employee, or Object, but not a subtype such as Executive.
Это противоречит его более раннему изданию, где в setFirst можно передавать Manager и Executive, но не их супертипы.
Одновременно у Эккеля аналогичная цитата:
the argument is now a List<? super T>, so the List holds a specific type that is derived from T; thus it is safe to pass a T or anything derived from T as an argument to List methods.
Впрочем, эксперимент подтверждает правоту Эккеля:
( Read more... )