Skip to content

Commit 3817341

Browse files
authored
Merge pull request #2237 from smowton/smowton/feature/initialize-class-literals
Java class literals: init using a library hook when possible
2 parents 70f13f3 + 4eda8ad commit 3817341

23 files changed

+288
-9
lines changed
154 Bytes
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
public @interface ExampleAnnotation {
3+
4+
}
668 Bytes
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
public enum ExampleEnum {
3+
4+
}
5+
113 Bytes
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
interface ExampleInterface {
3+
4+
}
110 Bytes
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
; Compile me with Jasmin 2.1+ (https://sourceforge.net/projects/jasmin/)
2+
3+
.class public synthetic ExampleSynthetic
4+
.super java/lang/Object
1.23 KB
Binary file not shown.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
public class Test {
3+
4+
public static void main() {
5+
6+
assert ExampleAnnotation.class.isAnnotation();
7+
assert ExampleInterface.class.isInterface();
8+
assert ExampleEnum.class.isEnum();
9+
assert ExampleSynthetic.class.isSynthetic();
10+
11+
assert char[].class.isArray();
12+
assert short[].class.isArray();
13+
assert int[].class.isArray();
14+
assert long[].class.isArray();
15+
assert float[].class.isArray();
16+
assert double[].class.isArray();
17+
assert boolean[].class.isArray();
18+
assert Object[].class.isArray();
19+
assert Object[][].class.isArray();
20+
21+
// Note use of '==' not '.equals', as we expect the same exact literal,
22+
// which in jbmc always have the same address.
23+
// Note names of array classes are not tested yet, as arrays' types are
24+
// printed as their raw signature, to be addressed separately.
25+
// Note also primitive types (e.g. int.class) are not addresses here, as
26+
// they are created through box types' static initializers (e.g. Integer
27+
// has a static member TYPE that holds the Class for `int.class`)
28+
29+
assert ExampleAnnotation.class.getName() == "ExampleAnnotation";
30+
assert ExampleInterface.class.getName() == "ExampleInterface";
31+
assert ExampleEnum.class.getName() == "ExampleEnum";
32+
33+
}
34+
35+
}

0 commit comments

Comments
 (0)