Odd compiler behavior (re: generics)

Greetings, I am encountering a rather odd compiler generated error/warning with some code. The issue involves using an "independent" generic method of a raw-typed class. That is, the class has a variable T (call it Test<T> and has an instance method that returns ArrayList<String>. The problem: when a raw typed Test is used, theArrayList returned is also raw. Here is some code to illustrate:

import java.util.ArrayList;

class Test<T>{

ArrayList<String> getChildren(){

returnnull;

}

staticvoid test1( Test t ){

ArrayList<String> children = t.getChildren();

// WARNING: ^^^^^^^^^^^^^^^^

//Test.java:26: warning: [unchecked] unchecked conversion

//found: java.util.ArrayList

//required: java.util.ArrayList<java.lang.String>

}

staticvoid test2( Test<?> t ){

// OK, since we have the type variable set.

ArrayList<String> children = t.getChildren();

}

If the type variable is specified as anything but raw, then it works fine.

Is there some explantation for this behavior? My argument: since the return type of getChildren doesn't use the wildcard, why does the type argument of the implicit instance matter? Is this a compiler bug or just a "sharp edge" in the specification (perhaps even reasonable or necessary).

I know the solution (or workaround). I am just seeking an explanation.

Thanks,

- Tim

[2097 byte] By [Tim.Bauera] at [2007-10-2 22:48:31]
# 1

I found a bug evaluation (6358084) that was closed as not a bug where

the evaluator wrote:

All members, regardless of their dependence of type parameters, are erased.

So the compiler is correct, the method call is unchecked.

Still, I am ignorant of the reasoning for independent or fully described types.

Tim.Bauera at 2007-7-14 6:02:52 > top of Java-index,Developer Tools,Java Compiler...
# 2
Try reposting in the generics forum (and specifically point out that you are reposting because no one answered here.)
jschella at 2007-7-14 6:02:52 > top of Java-index,Developer Tools,Java Compiler...