Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / June 2005

Tip: Looking for answers? Try searching our database.

Java 1.5 generics warning messages

Thread view: 
RC - 29 Jun 2005 13:17 GMT
Since I upgrade Java from 1.4.2 to 1.5.002, each time
I got those generics warning messages.
Please help me get rid those messages.

public class MyClass {
  private Vector vector;

  public MyClass(Vector vector) { this.vector = vector; }

  public Vector getVector() { return vector; }
  public void addVector(Object object) { vector.addElement(object); }
}

....

MyClass dude = new MyClass(new Vector<String>());

dude.addVector("The Hell");
// Here I got warning from MyClass addVector method

warning: [unchecked] unchecked call to addElement(E) as a member of the
raw type java.util.Vector
                vector.addElement(object);

Vector<String> vv = dude.getVector();
// Here I also get warning message

warning: [unchecked] unchecked cast
found   : java.util.Vector
required: java.util.Vector<String>
 Vector<String> vv = (Vector<String>)dude.getVector();

Can someone out there help me get rid those warning messages?
Thank Q very much in advance!!
Ingo R. Homann - 29 Jun 2005 13:54 GMT
Hi RC,

you are mixing generics and non-generic code. Try the following:

 public class MyClass<T> {
   private Vector<T> vector;

   public MyClass(Vector<T> vector) { this.vector = vector; }

   public Vector<T> getVector() { return vector; }
   public void addVector(T object) { vector.addElement(object); }
 }

Ciao,
Ingo
Tjerk Wolterink - 29 Jun 2005 21:34 GMT
> Since I upgrade Java from 1.4.2 to 1.5.002, each time
> I got those generics warning messages.
[quoted text clipped - 30 lines]
> Can someone out there help me get rid those warning messages?
> Thank Q very much in advance!!

You can just ignore those warning message if you want your app to be compatible
with java 1.4
Dale King - 30 Jun 2005 06:24 GMT
>> Since I upgrade Java from 1.4.2 to 1.5.002, each time
>> I got those generics warning messages.
[quoted text clipped - 34 lines]
> compatible
> with java 1.4

That's not really an issue in this case, since the OP is actually using
generics so he will not be compatible with 1.4. The issue is that he is
mixing generics with non-generics.

Signature

 Dale King

Tjerk Wolterink - 30 Jun 2005 16:49 GMT
> That's not really an issue in this case, since the OP is actually using
> generics so he will not be compatible with 1.4. The issue is that he is
> mixing generics with non-generics.

ow my fault.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.