-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMain.java
More file actions
60 lines (50 loc) · 2.03 KB
/
Copy pathMain.java
File metadata and controls
60 lines (50 loc) · 2.03 KB
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
public class Main {
private static final class JavaAccumulator implements trait_implementors.Accumulator {
private int value;
JavaAccumulator(int initial) {
value = initial;
}
@Override
public int add(int amount) {
value += amount;
return value;
}
@Override
public int current() {
return value;
}
}
private static final class JavaProjector
implements trait_implementors.Projector_Dyn_Output_i64 {
private long bias;
JavaProjector(long bias) {
this.bias = bias;
}
@Override
public long project(int value) {
bias += 2;
return value * 100L + bias;
}
}
public static void main(String[] args) {
JavaAccumulator accumulator = new JavaAccumulator(10);
int exercised = trait_implementors.trait_implementors.exercise_accumulator(accumulator);
if (exercised != 1543 || accumulator.current() != 13) {
throw new AssertionError("Java accumulator did not dispatch through &mut dyn Accumulator");
}
JavaAccumulator left = new JavaAccumulator(1);
JavaAccumulator right = new JavaAccumulator(10);
int combined = trait_implementors.trait_implementors.combine_accumulators(left, right);
if (combined != 38 || left.current() != 4 || right.current() != 15) {
throw new AssertionError("Multiple Java trait objects lost identity or mutable state");
}
JavaProjector projector = new JavaProjector(5);
long projected = trait_implementors.trait_implementors.exercise_i64_projector(projector);
if (projected != 516L) {
throw new AssertionError("Associated-type trait object used the wrong specialized ABI");
}
if (trait_implementors.trait_implementors.rust_projector_smoke() != 57L) {
throw new AssertionError("Rust and Java implementors do not share the same trait-object ABI");
}
}
}