contravariant argument types: wanna?

Justin Johansson procode at adam-dott-com.au
Wed Sep 23 15:49:03 PDT 2009


Ary Borenszweig Wrote:
> Andrei Alexandrescu wrote:
> > class JamesBond : Driver {
> >     // James Bond can drive any auto vehicle
> >     // Contravariance needed here
> >     override void drive(AutoVehicle c) { ... }
> > }
> > 
> > Now if what you have is a JamesBond and a Truck, you need contravariance 
> > to have him drive it. (A HotGirl may or may not be present in the scene.)
> 
> So it should be:
> 
> class JamesBond : Driver {
>    override void drive(Object c) { ... }
> }
> 
> because JamesBond can even drive a HotGirl!

Yes, but if such occasion arises, it's a call for contraception not contravariance ;-)




More information about the Digitalmars-d mailing list