This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector.add() compiler warning

 
Meena R. Krishnan
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I get a compiler warning


What does the second part of the warning mean?
 
Mike Petrogeorge
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
chandra reddy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Krishna

Vector takes only Objects not primitive types.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic