• Post Reply Bookmark Topic Watch Topic
  • New Topic

Type parameter heritage scope  RSS feed

 
John Crichton
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,



I don't quite understand why T's heritage isn't visible? This means I have
to define T for every such method, phanta phoodoo!

thanks
 
Vijitha Kumara
Bartender
Posts: 4002
42
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you talking about this method


You don't need to define T here because Type Foo defines it at the top.
 
John Crichton
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, I just don't understand why I have to cast b when
calling foo1 to make it compile.



I figure it's because of type erasure, but I don't quite
understand why? I have to cast b because the compiler
requires a T, but type Bar is a T?
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, not necessarily. T extends Bar, so T could very well be a SubBar if SubBar extends Bar. And then b is no longer valid for method foo1.
 
John Crichton
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:No, not necessarily. T extends Bar, so T could very well be a SubBar if SubBar extends Bar. And then b is no longer valid for method foo1.


ah, now I see. Many thanks Rob!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!