标签:
1. java中的多重继承传递不同的StringProcessor实现类,将会分别做不同的事情
public abstract class StringProcessor implements Processor { public String name() { return getClass().getSimpleName(); } public abstract String process(Object input); public static String s = "If she weighs the same as a duck, she's made of wood"; public static void main(String[] args) { Apply.process(new Upcase(), s); Apply.process(new Downcase(), s); Apply.process(new Splitter(), s); } } class Upcase extends StringProcessor { public String process(Object input) { // Covariant return return ((String) input).toUpperCase(); } } class Downcase extends StringProcessor { public String process(Object input) { return ((String) input).toLowerCase(); } } class Splitter extends StringProcessor { public String process(Object input) { return Arrays.toString(((String) input).split(" ")); } }
标签:
原文地址:http://blog.csdn.net/zdp072/article/details/43088323