• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Generic Method declaration  RSS feed

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from john myer's mock test.

I just playing around with the code, and wonder why we can declare method at #1 and #2?? what is the logic?

String is part of <? super String>

 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

why we can declare method at #1 and #2


we can't!

List<? super String> can take a String or a superclass of String as a type argument. List<String> can have only a String type argument. The compiler cannot be sure that you would always pass in a List<String> since List<? super String> also allows a List<Object>. Hence, disallowed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!