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

generic class: what am i doing wrong?

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Garrett! any ideas on where i can find information on generics?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could with the Sun Java Tutorial chapters on generics: here and then here
 
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic