RFR: 8261006: 'super' qualified method references cannot occur in a static context

Vicente Romero vromero at openjdk.java.net
Fri Jun 25 15:39:06 UTC 2021


On Thu, 24 Jun 2021 04:14:07 GMT, Srikanth Adayapalam <sadayapalam at openjdk.org> wrote:

> Do we need to invent a new diagnostics for this ?
> 
> I think it is better to check why we fail to issue the existing diagnostic compiler.err.non-static.cant.be.ref for the test case in question.
> 
> See that in the following simple test case:
> 
> ```
> public class X {
>     interface I {
>         int doit();
>     }
>     void foo() {
>         I i = super::hashCode; // OK.
>     }
>     static void goo() {
>         I i = super::hashCode; // Error
>     }
> ```
> 
> JDK16 does report correctly:
> 
> X.java:9: error: non-static variable super cannot be referenced from a static context
> I i = super::hashCode; // Error
> ^
> 1 error

right I could reuse one of the already existing error messages but given that the spec explicitly mentions the case of `super` qualified method references, my thinking is that there could be a explicit error message for that case, just to give users a better idea of what is wrong and why

-------------

PR: https://git.openjdk.java.net/jdk/pull/4376


More information about the compiler-dev mailing list