GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Vector.add() compiler warning Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Vector.add() compiler warning" Watch "Vector.add() compiler warning" New topic
Author

Vector.add() compiler warning

Meena R. Krishnan
Ranch Hand

Joined: Aug 13, 2006
Posts: 178


I get a compiler warning


What does the second part of the warning mean?
Mike Petrogeorge
Greenhorn

Joined: Feb 13, 2007
Posts: 3
Normally, you don't worry about it. However, for the SCJP, or if your doing any generic programming, you need to worry about it.

If you change the declaration to Vector<Integer> v = new Vector<Integer>() your compiler should shut up. I have not looked, but hopefully there is another thread that talks about generics and there you can study the details of that declaration statement.
P Lavti
Ranch Hand

Joined: Mar 27, 2007
Posts: 65
As of Java 5, the <E> syntax is the way that you declare a collection's type. Prior to Java 5 there was no way to specify the type of a collection.
In Java 5, if you are sure that your Vector (or in general your Collection) will contain only one type of objects say String, then you decalre it as:

Vector <String> vec = new Vector <String> ();
vec.add("Hello");
[ April 12, 2007: Message edited by: P Lavti ]

-P Lavti<br />SCJP 5.0 (88%)
chandra reddy
Greenhorn

Joined: Apr 11, 2007
Posts: 10
Hello Krishna

Vector takes only Objects not primitive types.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Originally posted by chandu:
Hello Krishna

Vector takes only Objects not primitive types.


We are discussing Java 5.0 here where primitive types may be autoboxed into their corresponding wrapper types.
[ April 13, 2007: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
GeeCON Prague 2014
 
subject: Vector.add() compiler warning