• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

passing List<? super Number> to method teeth(List<Object> type)

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is based on a question from CertPal.



Doesn't type Object qualify as a type capable of receiving ? super Number?

Thanks.

Matt

 
Saloon Keeper
Posts: 12605
273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. List<? super Number> means it could be a list of any type that is a supertype of Number. The problem is that the compiler can't say what type exactly. So it could be a List<Number> as well as a List<Object>. And in Java you can't assign List<SubType> to List<SuperType>, so the compiler can't guarantee that what you're doing is legal.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can assign a List<Object> to a List<? super Number> reference - but not vice-versa, which is what you're effectively doing when trying to call that method. A List<? super Number> reference might, for instance, point to a List<Number>.
 
matt love
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Stephan and Matthew.
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic