1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
class
Unsafepublish {
private
String[] states={
"AK"
,
"AL"
};
public
String[] getStates(){
return
states;
}
public
static
void
main(String[] args) {
UnSafeStates safe =
new
UnSafeStates();
System.out.println(Arrays.toString(safe.getStates()));
safe.getStates()[
1
] =
"c"
;
System.out.println(Arrays.toString(safe.getStates()));
}
}
|
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
|
public
class
Escape{
private
int
thisCanBeEscape =
0
;
public
Escape(){
new
InnerClass();
}
private
class
InnerClass {
public
InnerClass() {
//这里可以在Escape对象完成构造前提前引用到Escape的private变量
System.out.println(Escape.
this
.thisCanBeEscape);
}
}
public
static
void
main(String[] args) {
new
Escape();
}
}
|