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

Generic class

 
Ranch Hand
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have written a code to use Generic classes,




The code works fine,but i want to know that why does a warning occurs during the casting from a to x,even though i have mentioned the relationship that T$ extends T?
Its very well understood that if i do not establish a relationship between T and T$,and then try to assign one type to other,compiler gives an error.But after 'T$ extends T;,if i assign T$ to T with casting,no warning occurred,so why in this case?
Any replies would be helpful.
Thanks...
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sudhanshu,

You're getting the warning not because of the assignment, but because of the cast.

The point of generic code is to prevent people from having to use casts. If you mix generic code and casts, the compiler will give you a warning. Essentially what it's saying is: "I can't check whether this code is correct, it might blow up at runtime".
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic