• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Generics

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi everybody,


I have this code:



Which of the following can be inserted at // to comile the code without error?

A. public static<T> List<T>backwards(List<T> input)
B. public static<T> List<T>backwards(List<? extends T> input)
C. public static<T> List<T>backwards(List<? super T> input)
D. public static<T> List<? extends T>backwards(List<T> input)
E. public static<T> List<? super T>backwards(List<T> input)
F. public static<? extends T> List<T>backwards(List<T> input)

The output is A,B,D,E.

I would like to know why letter B is correct instead of letter C ? Because in the code above there is a add method. I think that only List<? super T> could have a add method and not List<? extends T>.

Can anybody help me?
 
Mylene Morato
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok.
The source is learnkey MasterExam by K & B.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check here
 
reply
    Bookmark Topic Watch Topic
  • New Topic