bad highlighting of inferred static methods with generics
private static List ListToTypedList(Collection in) {
Iterator i = in.iterator();
List out = new ArrayList();
while(i.hasNext()){
out.add((E)i.next());
}
return out;
}
private static List buildFileList(CommandLine commandLine) {
List in = ListToTypedList(commandLine.getArgList());
Hi Guys great work on the generics implimentation, but unfortunatley the last line here highlights with an error
Incompatible types found: java.util.List, required java.util.List]]>
regards gary
Please sign in to leave a comment.
I don't know much about generics, so I could be totally wrong, but doesn't that line need to be
List in = listToTypedList(commandLine.getArgList()); ? Or maybe the ]]> goes after listToTypedList. I forget. Or, as I said, I could be wrong.
Dr Gary Thomspon wrote:
Please submit a report to Tracker.
Friendly,
Dmitry
--
Dmitry Lomov
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"
Is this really valid syntax? How is the compiler supposed to determine what E is in that context? I can understand that it's rather obvious in that example, but I'm sure there are many cases where it is not...
that line need to be
>
Neither do I, so I could also be totally wrong :) but I would say it should
be (as the error message says):
List in = ListToTypedList(commandLine.getArgList()); Unless the class is declared as List (or whatever the syntax is) and List]]> can be used instead, but I don't know if the
compiler handles this (and E extends String is also dubious, as String is
final).
I'm not too familiar with generics, but it looks like you're doing something like overloading based on return types. Assuming that this is not explicitly legal when using generics, you can't determine the return type until after the method runs (since you don't know what E is until you look at the Collection).
Keith Lea wrote:
Yes, it is valid according to generics-2.2. Value of E is inferred from
type of 'in' in line:
Friendly,
Dmitry
--
Dmitry Lomov
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"
Carlos Costa e Silva wrote:
>> I don't know much about generics, so I could be totally wrong, but
>> doesn't
>>
>> List in = ]]>listToTypedList(commandLine.getArgList());
The above is correct, although superflous, syntax. However, it is not
supported by IDEA at the moment.
I am afraid you are :)
E is defined only inside ListToTypedList body, so you cannot use it
here.
Friendly,
Dmitry
--
Dmitry Lomov
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"
>>List in = listToTypedList(commandLine.getArgList()); > >The above is correct, although superflous, syntax. >]]>However, it is not supported by IDEA at the moment.
Actually it is not only not supported by idea but also the generics 2.2 eap compiler produces an error "illegal start of expression.
Furthermore idea 887 highlights the error (though it does pop up an internal error dialog once before doing it...)
regards gary