<div dir="ltr">Hi Tagir,<div><br></div><div>This is expected behavior. See Chapter 15 of the Java Language Specification (Java SE 25 Edition) [1]:</div><div><font color="#444444"><br></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font color="#444444">Unlike a lambda expression, a method reference can be congruent with a generic function type (that is, a function type that has type parameters). </font></div><div><font color="#444444">This is because the lambda expression would need to be able to declare type parameters, and no syntax supports this; while for a method reference, </font></div><div><font color="#444444">no such declaration is necessary. For example, the following program is legal:</font></div><div><br><font face="monospace">interface ListFactory {<br>    <T> List<T> make();<br>}<br><br>ListFactory lf  = ArrayList::new;<br>List<String> ls = lf.make();<br>List<Number> ln = lf.make();</font><br></div></blockquote><br><div>Glavo</div><div><br></div><div>[1]: <a href="https://docs.oracle.com/javase/specs/jls/se25/html/jls-15.html#jls-15.27">https://docs.oracle.com/javase/specs/jls/se25/html/jls-15.html#jls-15.27</a></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Wed, Oct 8, 2025 at 12:12 AM Tagir Valeev <<a href="mailto:amaembo@gmail.com">amaembo@gmail.com</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">Hello!<div><br></div><div>I'm investigating a seemingly weird compilation case. Consider the following Java interface:</div><div><br></div><div>import java.util.function.Supplier;<br><br>interface Main {<br>    interface X<T> {<br>        X<T> self();<br>    }<br><br>    static X<?> makeX() {return null;}<br><br>    static <R> X<R> create(Supplier<? extends R> supplier) {return null;}<br> <br>    static X<X<?>> methodRef() {<br>        return create(Main::makeX).self();<br>    }<br><br>    static X<X<?>> lambda() {<br>        return create(() -> makeX()).self();<br>    }<br>}</div><div><br></div><div>I expect that either both methods 'methodRef' and 'lambda' should be compilable or both should be non-compilable. However, while 'methodRef' compiles, 'lambda' is rejected by compiler (using javac build 25+36-3489):</div><div><br>Main.java:17: error: incompatible types: X<X<CAP#1>> cannot be converted to X<X<?>><br>        return create(() -> makeX()).self();<br>                                         ^<br>  where CAP#1 is a fresh type-variable:<br>    CAP#1 extends Object from capture of ?<br>1 error<br>error: compilation failed</div><div><br></div><div>Could you please help me and clarify whether this is an expected behavior or not?</div><div><br></div><div>With best regards,</div><div>Tagir Valeev</div></div>
</blockquote></div>