OT: Java5 generics

I just stumbled above this little code monster and it costs me half an
our to find the reason. Still I don't understand it.
Can anybody explain it, please?

Code
-


import java.util.List;

public class TestType
{

public interface Generic { public List getStrings(); } public void iterate(Generic gen) { for(String o : gen.getStrings()) // javac error. IDEA suggests 'Object' { } } public void iterate(Generic]]> gen)
{
for(String o : gen.getStrings())
{
}
}

}

4 comments
Comment actions Permalink

This is confusing but apparently defined by the JLS:

"the result of the method call on raw qualifier is itself made raw according to JLS"
http://www.jetbrains.net/jira/browse/IDEA-6254#action_44214

Sascha

0
Comment actions Permalink

I already thought this as javac produces the same warning.
But do you know why?

BTW: a nice FAQ is
http://www.langer.camelot.de/GenericsFAQ/FAQSections/TechnicalDetails.html

Sascha Weinreuter schrieb:

This is confusing but apparently defined by the JLS:

"the result of the method call on raw qualifier is itself made raw
according to JLS"
http://www.jetbrains.net/jira/browse/IDEA-6254#action_44214

Sascha

0
Comment actions Permalink

AFAIK, this decision was made to force clients to use generic types ubiquitiously. The general policy, though sometimes broken, is to disallow "rare" i.e. mixed generic and raw types.

Eugene.

0
Comment actions Permalink

Thanks for the answer.

Eugene Vigdorchik schrieb:

AFAIK, this decision was made to force clients to use generic types ubiquitiously. The general policy, though sometimes broken, is to disallow "rare" i.e. mixed generic and raw types.

Eugene.

0

Please sign in to leave a comment.