Created
April 8, 2022 08:29
-
-
Save maciejwalkowiak/2aa982f4908aa5e896215543dd99f75d to your computer and use it in GitHub Desktop.
JDK-8141508 failing in 8.0.322
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://bugs.openjdk.java.net/browse/JDK-8141508 | |
package com.maciejwalkowiak; | |
import java.util.Optional; | |
import org.junit.jupiter.api.Test; | |
public class FooTest { | |
@Test | |
void foo() { | |
AB ab = new AB(); | |
X x = new X(); | |
x.process("string", ab); | |
} | |
} | |
class X { | |
<T extends A & B> void process(String s, T t) { | |
// this works: | |
// if (s != null) { | |
// t.foo(s); | |
// t.bar(s); | |
// } | |
Optional<String> optionalS = Optional.ofNullable(s); | |
optionalS.ifPresent(t::foo); | |
// this throws: | |
// java.lang.invoke.LambdaConversionException: Invalid receiver type interface com.maciejwalkowiak.A; | |
// not a subtype of implementation type interface com.maciejwalkowiak.B | |
optionalS.ifPresent(t::bar); | |
} | |
} | |
interface A { | |
void foo(String s); | |
} | |
interface B { | |
void bar(String s); | |
} | |
class AB implements A, B { | |
@Override public void foo(String s) { | |
System.out.println("foo " + s); | |
} | |
@Override public void bar(String s) { | |
System.out.println("bar " + s); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment