大哥们过来看看,想了快一个小时了.
package interfaces.interfaceprocessor;import java.util.*;
import interfaces.interfaceprocessor.Processor;
class Apply
{
public static void process(Processor p, Object s)
{
System.out.println("Using Processor " + p.name());
System.out.println(p.process(s));
}
}
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 name()
{
return getClass().getSimpleName();
}*/
public String process(Object input)
{
return ((String)input).toUpperCase();
}
}
class Downcase extends StringProcessor
{
/*public String name()
{
return getClass().getSimpleName();
}*/
public String process(Object input)
{
return ((String)input).toLowerCase();
}
}
class Splitter extends StringProcessor
{
/*public String name()
{
return getClass().getSimpleName();
}*/
public String process(Object input)
{
return Arrays.toString(((String)input).split(" "));
}
}
错误提示:
StringProcessor.java:8: 错误: 找不到符号
System.out.println("Using Processor " + p.name());
^
符号: 方法 name()
位置: 类型为Processor的变量 p
StringProcessor.java:9: 错误: 找不到符号
System.out.println(p.process(s));
^
符号: 方法 process(Object)
位置: 类型为Processor的变量 p