forked from rahulXbarnwal/JavaTutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLearnAnonymousClasses.java
More file actions
50 lines (32 loc) · 831 Bytes
/
LearnAnonymousClasses.java
File metadata and controls
50 lines (32 loc) · 831 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
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
package oops4;
// No constructor
// No name
// Used for short implementations
// Replaced mostly by Lambda expressions
public class LearnAnonymousClasses {
// this obj is of the anonymous subclass
OuterClass obj = new OuterClass() {
void sing() {
}
public void outerMethod() {
}
};
// object of anonymous class implementing SuperInterface
SuperInterface obj2 = new SuperInterface() {
@Override
public void interfaceMethod() {
}
};
// creation of object of anonymous class implementing functional interface
// using lambda functions / expressions
SuperInterface obj3 = () -> {
};
}
class OuterClass {
public void outerMethod() {
}
}
@FunctionalInterface
interface SuperInterface {
void interfaceMethod();
}