-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample.java
200 lines (194 loc) · 3.96 KB
/
example.java
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package com.test;
import java.util.*;
import java.util.functions.*;
import static java.lang.Math.*;
/** Test doc
Line 2
*/
public class Test {
public static int x = 3;
public static String str = "\nTest Line 1\nTest Line 2\n";
/**
* Test doc
* Line 2
*/
public static void main(String[] args) {
System.out.println("Program start!");
int x, y;
y = x = 5 * 23 + (int)Math.pow(6, 7);
IntFunction<String> itos = String::valueOf;
Function<? extends String, Integer> stoi = str -> {
return Integer.parseInt(str);
};
Supplier<StringBuilder> sbsupplier = StringBuilder::new;
var rand = new Random();
if(rand.nextBoolean()) {
System.out.println(stoi.apply(itos.apply(0b101110101)));
}
switch(rand.nextInt(10)) {
case 0, 1:
System.out.println("A");
break;
case 2, 3:
System.out.println("B");
break;
case 4:
System.out.println("C");
break;
case 5:
System.out.println("D");
break;
case 6, 7, 8:
System.out.println("E");
break;
case 9:
case 10:
System.out.println("F");
break;
default:
throw new AssertionError();
}
int[] ints = {1, 2, 3, 4};
int[] ints2[] = new int[5][];
char ch = switch(rand.nextInt(10)) {
case 0, 1 -> "A";
case 2, 3 -> "B";
case 4 -> "C";
case 5 -> "D";
case 6, 7, 8 -> "E";
case 9, 10 -> "F";
default -> throw new AssertionError();
};
char ch2 = switch(rand.nextInt(10)) {
case 0, 1:
break "A";
case 2, 3:
break "B";
case 4:
break "C";
case 5:
break "D";
case 6:
break "E";
case 8:
break "F";
default:
break "G";
};
label: {
int foo = 5;
for(@Annotation int i = 0; i > -10; i--) {
foo += i;
foo /= i;
System.out.println(foo);
}
}
int foo = 7;
for(x = 0; x < 10; x++) {
foo -= x;
foo *= x;
System.out.println(foo);
}
for(int i : ints) {
System.out.println(foo /= i);
}
abstract class Greeter {
Greeter() {
System.out.println("New " + this.getClass().getName() + " created!");
}
abstract void greet();
}
var v1 = 3; var v2 = new Greeter() {
void greet() {
System.out.println("hi!");
}
};
do
v1 += 2;
while({self.condition});
if(rand.nextBoolean()) {
System.out.println("A");
} else if(rand.nextInt(10) < 5) {
System.out.println("B");
}
int@Annotation [] ints2[] = new @Annotation int[3] @Annotation [];
for(int i : ints2) {
System.out.println(i);
}
for(int i = 3, j = 10; i < j; i += 2, (i += 2), j++) {
System.out.println(i + j);
}
List<String> list1 = java.util.List.of("first", "second", "third");
try {
list1.add("fourth");
} catch(RuntimeException | UnsupportedOperationException e) {
} catch(SecurityException | IllegalStateException e2) {
} catch(NullPointerException | ClassNotFoundException e3) {
}
try(Scanner scan = new Scanner(new File("missing.txt"))) {
scan.useDelimiter("\\A");
throw new AssertionError();
} catch(FileNotFoundException e) {
}
}
}
@interface Annotation {
Annotation[] value() default {};
}
class Thing {
final String id;
{
var b = new StringBuilder();
for(char c = "a"; c < "z"; c++) {
b.append(c);
}
id = b.toString();
}
@Annotation(@Annotation)
@SuppressWarnings("unused")
public Thing() {
System.out.println("New Thing created!");
}
@SuppressWarnings({"unchecked", "resource"})
public void doThing() {
synchronized(this) {
System.out.println(this.id);
}
return;
}
}
interface Interface {
void test();
int getId();
default String getName() {
return String.valueOf(this.getId());
}
void setName(String newname);
}
enum Day {
MONDAY("Mon."),
TUESDAY("Tues."),
WEDNESDAY("Wed."),
THURSDAY("Thurs."),
FRIDAY("Fri."),
@Annotation
SATURDAY("Sat.") {
@Override
public boolean isWeekend() {
return true;
}
},
SUNDAY("Sun.") {
@Override
public boolean isWeekend() {
return true;
}
};
public final String abbr;
Day(String abbr) {
this.abbr = abbr;
}
public boolean isWeekend() {
return false;
}
}