forked from BruceEckel/OnJava8-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDotNew.java
More file actions
25 lines (23 loc) · 700 Bytes
/
DotNew.java
File metadata and controls
25 lines (23 loc) · 700 Bytes
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
// innerclasses/DotNew.java
// (c)2020 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Creating an inner class directly using .new syntax
public class DotNew {
public class Inner {
public Inner() {
System.err.println("inner is be done");
}
}
public Inner getInner(){
return new Inner();
}
public static void main(String[] args) {
DotNew dn = new DotNew();
//fun1
DotNew.Inner dni = dn.new Inner();//self-note: 直接获取创建内部对象的方法, .new
//fun2
DotNew.Inner dni2 = dn.getInner();
DotNew.Inner dni3 = dn.getInner();
}
}