collectionclassifier.java
来自「java 进阶专用。」· Java 代码 · 共 29 行
JAVA
29 行
// Broken - incorrect use of overloading! - Page 128
import java.util.*;
public class CollectionClassifier {
public static String classify(Set s) {
return "Set";
}
public static String classify(List l) {
return "List";
}
public static String classify(Collection c) {
return "Unknown Collection";
}
public static void main(String[] args) {
Collection[] tests = new Collection[] {
new HashSet(), // A Set
new ArrayList(), // A List
new HashMap().values() // Neither Set nor List
};
for (int i = 0; i < tests.length; i++)
System.out.println(classify(tests[i]));
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?