*
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
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: 41106
    
  45
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?
 
Similar Threads
Generics Warnings
what is the code trying to say between inheritance and aggregation?
How the insertAtBack sets the next for head?
Java Stack program
Static nested class