-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApply.java
More file actions
executable file
·56 lines (40 loc) · 1.09 KB
/
Apply.java
File metadata and controls
executable file
·56 lines (40 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package thinkinjava.test9;
import java.util.Arrays;
public class Apply {
public static void process(Processor p, Object s) {
System.out.println("Using Processor " + p.name());
System.out.println(p.process(s));
}
public static String s = "Sisagreement with beliefs is by definition oncorrect";
public static void main(String[] args) {
process(new Upcase(), s);
process(new Downcase(), s);
process(new Splitter(), s);
}
}
class Processor {
public String name() {
return getClass().getSimpleName();
}
Object process(Object input) {
return input;
}
}
class Upcase extends Processor {
@Override
String process(Object input) {
return ((String) input).toUpperCase();
}
}
class Downcase extends Processor {
String process(Object input) {
return ((String) input).toLowerCase();
}
}
class Splitter extends Processor {
String process(Object input) {
return Arrays.toString(((String) input).split(" "));//���ַ�ʽ���Խ�һ���ַ�������һ���ַ�������
}
}
class animalsss extends Apply {
}