This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generic class: what am i doing wrong?

 
f. nikita thomas
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're mixing generic Node<T>s and raw Nodes:

 
f. nikita thomas
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Garrett! any ideas on where i can find information on generics?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could with the Sun Java Tutorial chapters on generics: here and then here
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic