Company Ghost Story 公司鬼故事 11

contents

  1. 1. Java
    1. 1.1. Over Overload
    2. 1.2. One-Format Multiple-Ways

Java

Over Overload

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class OhMyGod {
public void run() {System.out.println("A");}
public void run(String t) {System.out.println("B");}
public <T> void run(T[] t) {System.out.println("C");}
public <T> void run(T t) {System.out.println("D");}
public static void run(String... t) {System.out.println("E");}
public static void main(String[] args) {
new OhMyGod().run();
new OhMyGod().run(new String[0]);
new OhMyGod().run("1");
new OhMyGod().run("1", "2");
}
} // AEBE, little strange

One-Format Multiple-Ways

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class FileIn {
private boolean isCSV; // why not enum
private boolean isXML;
private boolean isJSON;
public void setIsCSV(boolean e) {isCSV = e;}
public void setIsXML(boolean e) {isXML = e;}
public void setIsJSON(boolean e) {isJSON = e;}
public void import(File file) {
// why not if-else
if (isCSV) CSVIn(file); //???
if (isXML) XMLIn(file); //???
if (isJSON) JSONIn(file); //???
}
}