• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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 ]
 
a wee bit from the empire
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic