<div dir="ltr"><div dir="ltr">Looks like a legitimate bug to me... <br></div><div><br></div><div>You'd think how the compiler treats a static method reference shouldn't be at all determined by whether the class containing that static method is generic or not...<br></div><div><br></div><div>I've created <a href="https://bugs.openjdk.org/browse/JDK-8309767">https://bugs.openjdk.org/browse/JDK-8309767</a> to track this.<br></div><div><br></div><div>-Archie</div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jun 9, 2023 at 11:59 AM Ethan McCue <<a href="mailto:ethan@mccue.dev">ethan@mccue.dev</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Following up on this just to see if there is an explanation of some sort I am missing.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Apr 30, 2023 at 8:40 AM Ethan McCue <<a href="mailto:ethan@mccue.dev" target="_blank">ethan@mccue.dev</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I've run into either a corner case in type resolution or a compiler bug and I'm not sure which.<br><br>In an expression context, if a static method is referenced from a generic class then it won't properly target overloads that require primitive wrapper unboxing.<br><br><font face="monospace">package org.example;<br><br>import java.time.Month;<br>import java.util.function.Supplier;<br><br><br>interface A {<br> static int f() {<br> return 1;<br> }<br>}<br><br>interface B<T> {<br> static int f() {<br> return 2;<br> }<br>}<br><br>final class C {<br> static int f() {<br> return 3;<br> }<br>}<br><br>final class D<T> {<br> static int f() {<br> return 4;<br> }<br>}<br><br><br>public class Main {<br> static void h(Month b) {}<br> static void h(int b) {}<br><br> static <T> T g(Supplier<? extends T> d) {<br> return d.get();<br> }<br><br><br> public static void main(String[] args) {<br> // Compiles<br> h(<br> g(A::f)<br> );<br><br> // Doesn't compile<br> h(<br> g(B::f)<br> );<br><br> // Compiles<br> var r1 = g(B::f);<br> h(r1);<br> <br> // Compiles<br> h(<br> g(C::f)<br> );<br><br> // Doesn't compile<br> h(<br> g(D::f)<br> );<br> <br> // Compiles<br> var r2 = g(D::f);<br> h(r2);<br> }<br>}</font><br></div>
</blockquote></div>
</blockquote></div><br clear="all"><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>