-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
58 lines (43 loc) · 1.57 KB
/
Copy pathTest.java
File metadata and controls
58 lines (43 loc) · 1.57 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
57
58
package test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class Test implements Serializable, Cloneable {
public Test() {
}
public static void main(String[] args) throws ClassNotFoundException, SQLException, InterruptedException {
if (null == getObject("test")) {
System.out.println("1");
}
if (getObject("test") != null) {
System.out.println("1");
}
try {
Test test1 = Test.class.newInstance();
// Test test2 = (Test) Constructor.class.newInstance(Test.class);
Test test2 = (Test)Class.forName("test.Test").newInstance();
Test test3 = new Test();
Test test4 = (Test) test3.clone();
ObjectOutputStream objo = new ObjectOutputStream(new FileOutputStream("Object1.txt"));
objo.writeObject(new Test());
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("Object1.txt"));
Test test5 = (Test) ois.readObject();
Test test6 = Test.class.getConstructor().newInstance();
System.out.println(test1 + " - " + test2 + " - " + test3 + " - " + test4 + " - " + test5 + " - " + test6);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Integer getObject(String key) {
Map<String, Integer> map = new HashMap<String, Integer>();
return map.get(key);
}
}