About Question com.enthuware.ets.scjp.v6.2.94 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
piotrkmiotczyk
Posts: 27
Joined: Mon Sep 22, 2014 1:30 pm
Contact:

About Question com.enthuware.ets.scjp.v6.2.94 :

Post by piotrkmiotczyk »

The purpose of this is confusing. Who exactly checks what the interface implementation has been typed to? Since the compiler checks anyway what the method accepts.

If play accepts Instrument args, it will fit Instrument and if will fit Guitar, so you can send polymorphic objects as arguments to it. It will not fit Object, so the play method implementation can safely work on Instruments it receives. Even if the whole class 'Implements Player' (with no generics), right?

I know the purpose of typing Collections is because otherwise there is no other mechanism to limit the type of things Collection can contain. But method declarations have this mechanism anyway.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.94 :

Post by admin »

All generics related information is checked (and then stripped off) by the compiler. Runtime has no knowledge of generics.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests