Thats why the Java language specification says the following:-
"The use of raw types is allowed only as a concession to compatibility of
legacy code. The use of raw types in code written after the introduction of
genericity into the Java programming language is strongly discouraged. *It
is possible that future versions of the Java programming language will
disallow the use of raw types.*
It is a compile-time error to attempt to use a type member of a
parameterized type as a raw type.
"
On Tue, Jul 1, 2008 at 8:08 PM, Dain Sundstrom <[EMAIL PROTECTED]> wrote:
> I find Java generics extremely confusing and if you ask me, their a
> gigantic hack. One thing in the long list of baffling things is the type of
> error you are seeing here...
>
> The main difference in the two examples is in the second AttributeBinding
> is a parameterized type. When you use the AttributeBinding type in the main
> method you do not provide parameters, so in the second example it is an
> non-generified declaration where as in the first example it is actually a
> properly generified type (since it has a no parameters, and yes this is
> super confusing).
>
> As you pointed out in the followup email, once you provide a type of the
> parameter the compiler starts working as expected. It seems that the
> compiler makes a simple decision that a type is properly gentrified or not,
> and if it is not generified, it ignores all generic declarations on the
> class (even the staticly declared ones like you have here).
>
> I avoid wildcard declarations <?> because the confuse the compiler when
> passing wildcard generics to methods. Instead I use <Object>, which is
> supposed to be the same thing as <?> but is isn't.
>
> It is kind of depressing how poorly generics work in Java.
>
> -dain
>
> On Jul 1, 2008, at 3:58 PM, David Blevins wrote:
>
> Anyone know why this works:
>>
>> public class Test {
>>
>> public interface AttributeBinding {
>>
>> public Object getAttribute();
>>
>> public List<Method> getMethod();
>>
>> }
>>
>> public static void main(String[] args) throws Exception {
>> AttributeBinding binding = null;
>> for (Method method : binding.getMethod()) {
>>
>> }
>> }
>> }
>>
>>
>> But this seems to somehow change the List<Method> to plain List and
>> generates a compile error:
>>
>> public class Test {
>>
>> public interface AttributeBinding<A> {
>>
>> public A getAttribute();
>>
>> public List<Method> getMethod();
>>
>> }
>>
>> public static void main(String[] args) throws Exception {
>> AttributeBinding binding = null;
>> for (Method method : binding.getMethod()) {
>>
>> }
>> }
>> }
>>
>>
>> Would love to know what the issue is.
>>
>> -David
>>
>>
>
--
Karan Singh Malhi