• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Vector.add() compiler warning

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I get a compiler warning


What does the second part of the warning mean?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Krishna

Vector takes only Objects not primitive types.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic