曰:马者,所以命形也;白者,所以命色也。命色者非名形也。故曰:“白马非马”。
— 公孙龙子
‘Horse’ is that by which we name the shape. ‘White’ is that by which we name the color. Naming the color is not naming the shape. So white horse is not horse.
— Gongsun Longzipublic class Horse extends Shape{ ... } public class WhiteHorse extends Horse implements Colourable { public Colour getColour(){ return Colours.WHITE; } public boolean equals( Object other ){ if ( !other instanceof WhiteHorse){ return false; } ... } } public class AnotherWhiteHorse{ public Shape getShape(){ return ShapeConstants.HORSE; } public Colour getColour(){ return Colours.WHITE; } } public class Argument{ public static void main(String[] args){ Horse horse = new Horse(); WhiteHorse whiteHorse = new WhiteHorse(); AnotherWhiteHorse anotherWhiteHorse = new AnotherWhiteHorse(); log.info( whiteHorse == Horse.class ); log.info( WhiteHorse.class == Horse.class ); log.info( WhiteHorse.class.equals( Horse.class ) ); log.info( whiteHorse == horse ); log.info( whiteHorse.equals ( horse ) ); log.info( anotherWhiteHorse == horse ); log.info( anotherWhiteHorse.equals ( horse ) ); log.info( anotherWhiteHorse instanceof Horse.class ); log.info( "Therefore white horse is not horse" ); } }
I’m speechless.