// VIM_TEST_SETUP let g:java_highlight_functions = 'style' // VIM_TEST_SETUP let g:java_highlight_generics = 1 // VIM_TEST_SETUP hi link javaGenericsC1 Todo // VIM_TEST_SETUP hi link javaGenericsC2 Error import java.math.BigInteger; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.LongFunction; import java.util.function.Predicate; class GenericsTests, U> { // JDK 21+. static final Function, Object> PARTIAL = GenericsTests.y0(); static final Function FACTORIAL_2000 = GenericsTests.y1() .apply(f -> x -> (x.compareTo(BigInteger.ONE) < 1) ? BigInteger.ONE : x.multiply(f.apply(x.subtract(BigInteger.ONE)))); static Y0 y0() { return (Function f) -> f.apply( GenericsTests.y0() .apply(f)); } static Y1 y1() { return (Function, Function> f) -> (T1 x) -> f.apply(GenericsTests.y1() .apply(f)) .apply(x); } static void noOp(T dummy) { } interface alpha { } interface Y0 extends Function, T1> { } interface Y1 extends Function, Function>, Function> { } interface Stackable extends Iterable { boolean isEmpty(); E peek(); E pop(); Stackable popAll(Stackable elements); Stackable popSome(Stackable elements, Predicate filter); Stackable push(E element); Stackable pushAll(Iterable elements); Stackable pushSome(Iterable elements, Predicate filter); Stackable wind(Consumer> action); } sealed interface Num { int radix(); N value(); } record Bin(N value) implements Num { public int radix() { return 2; } } record Dec(N value) implements Num { public int radix() { return 10; } } record Hex(N value) implements Num { public int radix() { return 16; } } record Oct(N value) implements Num { public int radix() { return 8; } } static Num fromDecimal(long x, int radix) { record Pair(LongFunction> a, LongFunction b) { } final Pair p = switch (radix) { case 2 -> new Pair(Bin::new, Long::toBinaryString); case 8 -> new Pair(Oct::new, Long::toOctalString); case 16 -> new Pair(Hex::new, Long::toHexString); default -> new Pair(Dec::new, y -> Long.toString(y)); }; return p.a().apply(Long.parseLong(p.b().apply(x), radix)); } static long toDecimal(Num x) { return Long.parseLong(switch (x) { case Bin(Long b) -> Long.toBinaryString(b); case Oct(Long o) -> Long.toOctalString(o); case Hex(Long h) -> Long.toHexString(h); default -> Long.toString(x.value()); }, x.radix()); } @java.lang.annotation.Target( java.lang.annotation.ElementType.TYPE_USE) @interface Taggable { String value() default ""; } { int N = 0, X = 1, Y = 2; Predicate f = y->N g = y->XN; boolean[] bb = { XY, X < Y, X klass = GenericsTests.class; Class< java.lang.Class<@Taggable("<>")int[][]> [] [] > [ ] [ ] $ [ ] [ ]; if (false) { new GenericsTests<>(); } alpha ao; alpha au; alpha> aau; alpha> ay0o; alpha> ay0u; Y0> y0ao; Y0> y0au; } }