aspose file tools*
The moose likes Beginning Java and the fly likes [error] unchecked call to add<E> as a member of the raw type of java.util.Vector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "[error] unchecked call to add<E> as a member of the raw type of java.util.Vector" Watch "[error] unchecked call to add<E> as a member of the raw type of java.util.Vector" New topic
Author

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

Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660



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.


Jon
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4490
    
    8

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

Joined: Apr 25, 2008
Posts: 660

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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [error] unchecked call to add<E> as a member of the raw type of java.util.Vector