Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions source/net.auoeke.dycon/Dycon.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.auoeke.dycon;

import java.lang.invoke.ConstantBootstraps;
import java.util.function.Supplier;
import java.util.function.*;

public class Dycon {
/**
Expand All @@ -28,6 +28,22 @@ Object lazyInvoke(Object... arguments) {
@throws RuntimeException if invoked at runtime (for example reflectively or without the compiler plugin)
*/
public static <T> T ldc(Supplier<T> initializer) {
throw new RuntimeException("Dycon::ldc may not be invoked at runtime");
throw new RuntimeException("Dycon#ldc(Supplier) may not be invoked at runtime");
}

public static boolean ldc(BooleanSupplier initializer) {
throw new RuntimeException("Dycon#ldc(BooleanSupplier) may not be invoked at runtime");
}

public static int ldc(IntSupplier initializer) {
throw new RuntimeException("Dycon#ldc(IntSupplier) may not be invoked at runtime");
}

public static long ldc(LongSupplier initializer) {
throw new RuntimeException("Dycon#ldc(LongSupplier) may not be invoked at runtime");
}

public static double ldc(DoubleSupplier initializer) {
throw new RuntimeException("Dycon#ldc(DoubleSupplier) may not be invoked at runtime");
}
}
8 changes: 5 additions & 3 deletions test/DyconTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.function.Supplier;

import org.junit.jupiter.api.Test;
import org.junit.platform.commons.annotation.Testable;
import sun.misc.Unsafe;
Expand All @@ -21,7 +23,7 @@ static Unsafe lazyLazyUnsafe() {
return ldc(DyconTest::lazyUnsafe);
}

Integer count(Object o) {
int count(Object o) {
return ldc(() -> count);
}

Expand All @@ -30,11 +32,11 @@ static <T> T allocateInstance(Class<T> type) {
}

static List<String> lazyStringList() {
return ldc(List::of);
return ldc(() -> List.of("Hello"));
}

static List<?> lazyList() {
return ldc(List::of);
return ldc(() -> List.of());
}

@Test void test() {
Expand Down