Skip to content

Instantly share code, notes, and snippets.

@imkiva
Last active August 26, 2022 09:02
Show Gist options
  • Save imkiva/8db13b6e578e473c1c9b977086bfe898 to your computer and use it in GitHub Desktop.
Save imkiva/8db13b6e578e473c1c9b977086bfe898 to your computer and use it in GitHub Desktop.
Java bug
import java.util.function.BiFunction;
public class Bug {
sealed interface Term {
record Lit() implements Term {}
record Lam(String x, Term a) implements Term {}
}
public static <X, T> void call(BiFunction<X, T, T> op, X x, T t) {
op.apply(x, t);
}
public static void main(String[] args) {
// this code works
call(Term.Lam::new, "x", (Term) new Term.Lit());
// this does not
call(Term.Lam::new, "x", new Term.Lit());
// java.lang.invoke.LambdaConversionException: Type mismatch for lambda argument 1:
// class java.lang.Record is not convertible to interface Term
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment