Page 1 of 1
About Question enthuware.ocpjp.v21.2.3313 :
Posted: Wed Jan 01, 2025 11:02 am
by Vadim.Benke
Given the following declarations:
Code: Select all
List<? super Booby> bV = null;
List<? extends Tooby> tV = null;
the statement
which is marked as a correct answer could actually only throw a null pointer exception.
Re: About Question enthuware.ocpjp.v21.2.3313 :
Posted: Wed Jan 01, 2025 11:40 pm
by admin
That's true but the question specifically says, "Which of the following statements will compile without any error?"
Re: About Question enthuware.ocpjp.v21.2.3313 :
Posted: Thu Jan 02, 2025 6:13 am
by Vadim.Benke
Indeed, you are right, thank you for the clarification.
As a practicing software developer it's hard to deal with senseless program code, I mean that which perfectly compiles but unconditionally throws an exception...
I have to learn to concetracte more on wording.
Re: About Question enthuware.ocpjp.v21.2.3313 :
Posted: Thu Jan 02, 2025 6:18 am
by admin
The purpose of this question is to test the reader on their understanding of generics and polymorphism. Generics are a compile time thing only. The rest of the code is just a prop.
Re: About Question enthuware.ocpjp.v21.2.3313 :
Posted: Thu Jan 02, 2025 11:01 am
by Vadim.Benke
Yes of course. As I wrote already - I have to learn deeply the difference between "compile", "run without exception", "doing nothing", "fully useless" for the test. In the practice I operate only with "it works" and "it doesn't".
If the lists would be initialized like ... = new ArrayList<>(); I would be more thinking about an .add, but I just skiped both add methods on null pointers as ... yes making no sense.

And needed even an extra pointing to the word "compile" after reading the explanation.

)