About Question com.enthuware.ets.scjp.v6.2.94 :
Posted: Mon Oct 27, 2014 4:54 am
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.
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.