Hi,
> This is part of the code(JDK 1.5 ,windows xp Chinese(simplified))
> ...
[quoted text clipped - 7 lines]
> it is not safe to use it.Why?Is not Integer an Object?And what is the
> right way?
The exact warning (in English) would be nice. I guess, you are using
Java5. Try this...
Vector<Integer> v=new Vector<Integer>();
v.addElement(new Integer(7));
...and read something about generics.
Hth,
Ingo
iherage@gmail.com - 21 Jun 2005 19:11 GMT
I read the java api doc of jdk 5.0 but it does not say anything about
it.It only says that the parameter is an element.
What about the other collections,LinkedList and ArrayList for
example?Do they have to use in this way?
Eric Olander - 21 Jun 2005 22:59 GMT
Generics were added to all the collection classes in 1.5. Check out
http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf
-Eric
>I read the java api doc of jdk 5.0 but it does not say anything about
> it.It only says that the parameter is an element.
> What about the other collections,LinkedList and ArrayList for
> example?Do they have to use in this way?
RC - 22 Jun 2005 16:25 GMT
> Hi,
>
[quoted text clipped - 17 lines]
>
> ...and read something about generics.
Great! This is very helpful to me.
But I have different situations.
What happen if I have lines:
Vector v = (Vector)vector.elementAt(i);
v.addElement(new Integer(7));
What should I do?
I wrote:
Vector<Integer> v = (Vector)vector.elementAt(i);
I still got warning
java:778: warning: [unchecked] unchecked conversion
found : java.util.Vector
required: java.util.Vector<java.lang.String>
Where I should put 2nd <Integer>?
Thank Q very much in advance!
Ingo R. Homann - 23 Jun 2005 07:48 GMT
Hi RC,
>> The exact warning (in English) would be nice. I guess, you are using
>> Java5. Try this...
[quoted text clipped - 27 lines]
>
> Thank Q very much in advance!
So, "v" is a Vector of Integers, and "vector" is a Vector of "Vector of
Integers"s? Then write this!
Vector<Integer> v;
Vector<Vector<Integer>> vector=...;
v=vector.elementAt(i);
v.addElement(7);
...and read something about "generics"!
Hth,
Ingo
PS: By the way, use ArrayList instead of Vector.