Why does Vector arise this Warning Note
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Trupti_Mehta
Posted On:   Tuesday, June 13, 2006 06:21 AM

I have noted, from Jdk1.4, when you use Vector in your class, on compilation it gives "Java uses unchecked or unsafe operations". Why is this warning note always on use of most Collections. I have seen in Vector, Array, Set. I just use addElement, elementAt, contains etc. Non of them are deprecated, or throws an exception or say, may not be suppotive in future versions. What does this Note mean & why do I see it since 1.4, why not before? I tried using just add instead of addElement (same way as used in previous versions), but that also didn't stop me from getting that Note. Their is also no substitution declared for Vector. I would like to know, where am I going wrong. Or what changes should I do to avoid such Notes.   More>>


I have noted, from Jdk1.4, when you use Vector in your class, on compilation it gives "Java uses unchecked or unsafe operations". Why is this warning note always on use of most Collections. I have seen in Vector, Array, Set.
I just use addElement, elementAt, contains etc. Non of them are deprecated, or throws an exception or say, may not be suppotive in future versions.


What does this Note mean & why do I see it since 1.4, why not before? I tried using just add instead of addElement (same way as used in previous versions), but that also didn't stop me from getting that Note. Their is also no substitution declared for Vector. I would like to know, where am I going wrong. Or what changes should I do to avoid such Notes. That Note is really bugging me. I like clean coding, hence don't prefer to see any errors or warnings in my compilation.


Please Any help is appreciated. Thanks


Trupti

   <<Less

Re: Why does Vector arise this Warning Note

Posted By:   Robert_Lybarger  
Posted On:   Tuesday, June 13, 2006 07:18 AM

You are seeing that in 1.5 as this is a new "generics" feature of the new language release. Google around for "java generics" and do some reading on the specifics. By example, if I as a coder knew ahead of time that a given Vector object would only ever store String objects, I would declare it this way:

Vector myVector = new Vector();

... and from then on, checks are made to ensure I am only add()'ing something which is an instance of String. On the other hand, if you use the old notation to declare the Vector, you'll get the warnings you are seeing, as you are using it in the non-type-safe "raw" mode that you've been otherwise used to using.
About | Sitemap | Contact