This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Study Gude Chap 7 Q16 (errata applied)

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given a method declared as:
public static <E extends Number> List<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;

my comments: E replaced by Integer,
which meets the return collection type <Integer>
and the generic declaration <Integer extend Number>.
ArrayList<Integer> should be campatible with List<Integer>
so this is a correct answer.


B. ArrayList<Integer> input = null;
List<Integer> output = null;

my comments: same reasoning as A, this is a correct answer.


C. ArrayList<Integer> input = null;
List<Number> output = null;

my comments: E replaced by Integer,
List<Number> violates the return collection type which should be
List<Integer>

D. List<Number> input = null;
ArrayList<Integer> output = null;

my comments: E replaced by Number,
ArrayList<Integer> violates the return collection type which should
be List<Number>


E. List<Number> input = null;
List<Number> output = null;

my comments: E replaced by Number,
which meets the return collection type List<Number>
and the generic declaration <Number extends Number>.
so this is a correct answer.


F. List<Integer> input = null;
List<Integer> output = null;

my comments: E replaced by Integer,
which meets the return collection type List<Integer>
and the generic declaration <Integer extends number>.
so this is a correct answer.

so my answer would be: ABEF

is it correct?
 
What's that smell? I think this tiny ad may have stepped in something.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic