|
|
Re: Generic Class in Non Generic class
|
Posted: Jun 21, 2006 11:58 PM
|
|
That doesn't make much sense, doas it?
You can't declare a instance variable without a class. The compiler must know what you want to to.
Here is what you basically try to do.
ArrayList ar = new ArrayList<String>(); //declared as ArrayList<Object>
ar.add("Hello");
ar.add(new Integer(5)); //this actually compiles, but during runtimme you could get some problems.
String s = ar.get(0); // compile error. get(0) returns Object
ar = new ArrayList<Integer>(); //still declared as ArrayList<Object>
ar.add(new Integer(5)); //using autoboxing here
Integer i = ar.get(0); //compile error
Tell me, what you try to achieve, then I might be able to help you find a solution for it.
|
|