gwtproject/gwt

Support private methods in interfaces

zbynek opened this issue · 4 comments

GWT version: 2.11
Browser (with version): all
Operating System: all


Description

As of Java 9 this is supported in Java: https://docs.oracle.com/en/java/javase/14/language/small-language-changes.html, but GWT support is missing

Steps to reproduce

Try compiling code with

public interface Greeter {
  public static String greet() {return concat("Hello", "World");}
  private static String concat(String a, String b) { return a + b; }
}

The following appears in log:

Illegal modifier for the interface method concat; only public, abstract, default, static and strictfp are permitted

Known workarounds

Make method public

Links to further discussions

#9869

I can't reproduce - are you sure you have sourceLevel set high enough? At this time, it still defaults to 8, you might want to set it to the java version in the rest of your project (or to auto to just use the jdk version that you're running with). Can you confirm?

I do however see a bug where interfaces annotated with jstype will appear to error out on private members:

if (!method.isAbstract() && method.getBody() != null) {
logError(member, "Native JsType method %s should be native or abstract.",
getMemberDescription(member));
}

In this case however, the error actually means "you forgot @JsOverlay" - but it is the same error message you get if you don't add default to a method with a body, so I still don't think there is a bug here (so much as a less helpful error message).

Indeed, sourceLevel was missing 🤦

What is "strictfp" in the error message?