Skip to content

Commit 2a5808e

Browse files
committed
新增:使用接口的接口案例
1 parent 945f4b6 commit 2a5808e

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.javacore.base.inter;
2+
3+
import java.util.Arrays;
4+
5+
/*
6+
* Copyright [2015] [Jeff Lee]
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
/**
22+
* @author Jeff Lee
23+
* @since 2015-12-1 13:04:30
24+
* 使用接口的接口案例
25+
*/
26+
interface ProcessorInter {
27+
String name();
28+
29+
Object process(Object input);
30+
}
31+
32+
class UpcaseImpl implements ProcessorInter {
33+
@Override
34+
public String name() {
35+
return this.getClass().getSimpleName();
36+
}
37+
38+
@Override
39+
public Object process(Object input) {
40+
return ((String)input).toUpperCase();
41+
}
42+
}
43+
44+
class SplitcaseImpl implements ProcessorInter {
45+
@Override
46+
public String name() {
47+
return this.getClass().getSimpleName();
48+
}
49+
50+
@Override
51+
public Object process(Object input) {
52+
return Arrays.toString(((String) input).split(" "));
53+
}
54+
}
55+
56+
public class ApplyInter {
57+
public static void process(ProcessorInter p , Object input){
58+
System.out.println("调用对象名:" + p.name());
59+
System.out.println(p.process(input));
60+
}
61+
62+
public static String s = "BYSocket's Blog is www.bysocket.com";
63+
public static void main(String[] args) {
64+
process(new UpcaseImpl(),s);
65+
process(new SplitcaseImpl(),s);
66+
}
67+
}

0 commit comments

Comments
 (0)