Re[5]: Генерики, наследование
От: aka50 Россия  
Дата: 16.05.07 11:23
Оценка: 13 (2)
Здравствуйте, Petrovich_Alex, Вы писали:

P_A>Здравствуйте, bolshik, Вы писали:


A>>дадим один фейковый параметр, из которого компилятор может попытаться вывести тип:


P_A>что то, здесь я не нашел про фейковый параметр.


Это было про List<Object> т.е. про несовместимость типов. Про необходимость фейк-параметра здесь

If the type parameter does not appear in the types of the method arguments, then the compiler cannot infer the type arguments by examining the types of the actual method arguments. If the type parameter appears in the method's return type, then the compiler takes a look at the context in which the return value is used. If the method call appears as the righthand side operand of an assignment, then the compiler tries to infer the method's type arguments from the static type of the lefthand side operand of the assignment

далее по тексту:
An invocation context other than an assignment is not considered for type inference. The result of the method call might be passed as an argument to another method, for instance. The compiler does not try to perform any special type inference in that case. Instead the compiler handles the method call as though it would appear in no context. No context means that the compiler performs the type inference algorithm as though the method result was assigned to a variable of type Object .

Как видишь, у нас тут никакого assigment-а нету, следовательно нету и inference, а значиццо будет MyFilter<Object>. Но если мы поможем компилятору и дадим ему параметр (чтобы сработал inference) то тип будет выведен. Т.е. данной задаче нужно придумать такую конструкция параметра фабрики, чтобы можно было вывести тип. Либо указывать его явно (что ИМХО более правлильное решение).
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.