File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes generic class: what am i doing wrong? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "generic class: what am i doing wrong?" Watch "generic class: what am i doing wrong?" New topic
Author

generic class: what am i doing wrong?

f. nikita thomas
Ranch Hand

Joined: Mar 02, 2008
Posts: 87


warnings/errors:

javac -Xlint:unchecked GenericStack.java
GenericStack.java:10: warning: [unchecked] unchecked call to Node(T) as a member of the raw type GenericStack.Node
first = new Node(item);
^
GenericStack.java:17: warning: [unchecked] unchecked cast
found : java.lang.Object
required: T
T obj = (T)first.obj;
^
2 warnings


so what is the safe way of doing this without the cast? are there any resources for generics on the web? my textbook glazed over this like the plague. thanks.

nikita


Imagination is more important than knowledge "Albert Einstein"
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
You're mixing generic Node<T>s and raw Nodes:



Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
f. nikita thomas
Ranch Hand

Joined: Mar 02, 2008
Posts: 87
thanks Garrett! any ideas on where i can find information on generics?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
You could with the Sun Java Tutorial chapters on generics: here and then here


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: generic class: what am i doing wrong?