• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[error] unchecked call to add<E> as a member of the raw type of java.util.Vector

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


Error
javac -Xlint TestTwelve.java
TestTwelve.java:21: warning: [unchecked] unchecked call to add(E) as a member of
the raw type java.util.Vector
chessFonts.add(allfonts[j].getFontName());
^
1 warning



"This is the consequence of a somewhat unfortunate limitation of generic types in Java.
For compatibility, the compiler translates all typed array lists into raw ArrayList objects
after checking that the type rules were not violated. In a running program, all array lists
are the same—there are no type parameters in the virtual machine. Thus, the casts
(ArrayList) and (ArrayList<Employee>) carry out identical runtime checks.
There isn’t much you can do about that situation. When you interact with legacy code,
study the compiler warnings and satisfy yourself that the warnings are not serious. "

Core Java Volume 1 (8th Edition) Pg. 211


Chess symbols article at http://en.wikipedia.org/wiki/Chess_symbols_in_Unicode.
Code sourced from an article.

 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. What's the question?

You should always use generic types, unless you really have no choice. Change Vector to Vector<String> (or whatever type Font.getFontName() returns) and the warning (warning, not error) will go away.
 
Jon Camilleri
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:Yes. What's the question?

You should always use generic types, unless you really have no choice. Change Vector to Vector<String> (or whatever type Font.getFontName() returns) and the warning (warning, not error) will go away.



It works as follows:



Now I'm just wondering how to read the String myChessPiece, because it will return '?' to the console, so I'm wondering whether there is a problem with the language environment.

NOTE: The copy to clipboard function on this forum does not work in my environment (Google Chrome/WinXP SP3).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic