Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

About Chapter 7: Generics and Collections

 
Ranch Hand
Posts: 37
IntelliJ IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In self test number 16th. I find a problem,it seems that every answer is wrong!!,why?

16.Given a method declared as:

public static <E extends Number> List<? super E> process(List<E> nums)

A programmer wants to use this method like this:

// INSERT DECLARATIONS HERE
output = process(input);
Which pairs of declarations could be placed at // INSERT DECLARATIONS HERE to allow the code to compile? (Choose all that apply.)

A. ArrayList<Integer> input = null;

ArrayList<Integer> output = null;

B ArrayList<Integer> input = null;

List<Integer> output = null;

c ArrayList<Integer> input = null;

List<Number> output = null;

d List<Number> input = null;

ArrayList<Integer> output = null;

e List<Number> input = null;

List<Number> output = null;

f List<Integer> input = null;

List<Integer> output = null;

g None of the above.

I try out every answer,but it compile wrong! Who can tell me why and explain how this work?

The compiler say:"Type mismatch: cannot convert from List<capture-of ? super Integer> to List<Number>" WHY
What it means "capture-of ?".I used following codes in eclipse3.3.

[ June 03, 2007: Message edited by: Zhao zhenhua ]
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the K&B Errata. Link is available on the top of the SCJP forum.

The declared method is:


public static <E extends Number> List<E> process(List<E> nums)


Thanks,
 
Zhao zhenhua
Ranch Hand
Posts: 37
IntelliJ IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the method just is what you say,the answer is right ,Thank you Chandra
 
Slideshow boring ... losing consciousness ... just gonna take a quick nap on this tiny ad ...
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic