mirror of
https://github.com/corda/corda.git
synced 2025-01-06 05:04:20 +00:00
69426b9945
For lambdas that implement java.io.Serializable, the compiler emits calls to LambdaMetaFactory.altMetafactory, not LambdaMetaFactory.metafactory, so I've provided a stub implementation that ignores that currently ignores the extra parameters it receives. This also fixes a bug in compiling lambda glue code for lambdas that take longs and/or doubles.
61 lines
1.3 KiB
Java
61 lines
1.3 KiB
Java
public class InvokeDynamic {
|
|
private final int foo;
|
|
|
|
private InvokeDynamic(int foo) {
|
|
this.foo = foo;
|
|
}
|
|
|
|
private interface Operation {
|
|
int operate(int a, int b);
|
|
}
|
|
|
|
private interface Operation2 {
|
|
long operate(long a, int b);
|
|
}
|
|
|
|
private static class Pair<A, B> {
|
|
public final A first;
|
|
public final B second;
|
|
|
|
public Pair(A first, B second) {
|
|
this.first = first;
|
|
this.second = second;
|
|
}
|
|
}
|
|
|
|
private interface Supplier<T> extends java.io.Serializable {
|
|
T get();
|
|
}
|
|
|
|
private static void expect(boolean v) {
|
|
if (! v) throw new RuntimeException();
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
int c = 4;
|
|
Operation op = (a, b) -> a + b - c;
|
|
expect(op.operate(2, 3) == (2 + 3) - 4);
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
new InvokeDynamic(i).test();
|
|
}
|
|
}
|
|
|
|
private void test() {
|
|
{ int c = 2;
|
|
Operation op = (a, b) -> ((a + b) * c) - foo;
|
|
expect(op.operate(2, 3) == ((2 + 3) * 2) - foo);
|
|
}
|
|
|
|
{ int c = 2;
|
|
Operation2 op = (a, b) -> ((a + b) * c) - foo;
|
|
expect(op.operate(2, 3) == ((2 + 3) * 2) - foo);
|
|
}
|
|
|
|
{ Supplier<Pair<Long, Double>> s = () -> new Pair<Long, Double>(42L, 77.1D);
|
|
expect(s.get().first == 42L);
|
|
expect(s.get().second == 77.1D);
|
|
}
|
|
}
|
|
}
|