Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SCJP Chapter 7, Question #16

 
Eduardo Mendes
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

can anyone help with this. I am using SCJP5 Study Guide, and have a problem on the question 16 of the Chapter 7 self test. There is no way my compiler (Eclipse, compliance 5.0) gives me the results as told in the book answer. Actually, the compiler says all three answers (B, E and F) are INCORRECT, i.e. it does not compile if I use any of those options. Did anyone face the same issue, or am I missing something here?

Many thanks for your help!
Eduardo
 
Vishal Matere
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eduardo Mendes:
I am using SCJP5 Study Guide, and have a problem on the question 16 of the Chapter 7 self test.
Eduardo


Can you post the actual question here. Many people may not be using same book or they may have already done SCJP hence done refer any book anymore.
It will be useful if you post actual question, so that even if somebody answer from Book atleast we come to know what question was...
 
Eduardo Mendes
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, pardon me.

Given a method declared as
public static <E extends Number> List<? super E> process(List<E> nums)

// INSERT CODE HERE
output = process(input);

Which pairs of declarations could be placed at // INSERT CODE HERE

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

Before I tried to code this, I thought 'C' would be the right answer. But my compiler tells me it's G...

I wonder if I should just give up on this exame... :-(

Thanks again for the help!
 
Eduardo Mendes
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. The book is Kathy's. I thought that was 'default' here :-)
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eduardo,

Somehow you've gotten an old, old copy of the book! This was an errata (you can find a link to a list of errata at the top of this forum), from a long time ago.

Instead of List<? super E>

it should read:

List<E>

hth,

Bert
 
Eduardo Mendes
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bert,

thank you so much. Wasn't expecting an answer from one of the authors himself! :-)

Best wishes,
Eduardo
 
kishor kalapa
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI all,
k&b pg 621
-----------------------------------------------------------------------------
Given a method declared as
public static <E extends Number> List<E> process(List<E> nums)

// INSERT CODE HERE
output = process(input);

Which pairs of declarations could be placed at // INSERT CODE HERE

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
---------------------------------------------------------------------------------
As per K&B book ans:-B,E,F
but i think 'A' also correct because return type follows polymorphism so if
return type is ArrayList also it can handle by List,Is it correct?
 
kishor kalapa
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please light on this..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic