Sep. 22nd, 2011

balu: (lambda-memed)
А вы знаете, почему разные авторы диаметрально противоположно описывают маски с ограничением 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... )

Profile

balu: (Default)
от. Михайло

December 2025

S M T W T F S
 123 456
7 8910111213
14151617181920
21222324252627
28293031   

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 29th, 2026 06:46 pm
Powered by Dreamwidth Studios