I have three types, A
, B
, and C
, which are defined as follows:
public sealed interface A extends Comparable<A> permits B<?>, C { ...
public non-sealed interface B<T> extends A { ...
public record C(String s, int i) implements A { ...
Everything compiles and works fine in Eclipse. Now when I run a gradle build, I get an error error: '{' expected
at the place of the opening bracket at permits B<?>
. When I remove <?>
, so that the type definition is as follows (raw type):
public sealed interface A extends Comparable<A> permits B, C { ...
...then gradle doesn't complain and the build is successful. Is this a gradle bug or is the type definition I am using not allowed?
CodePudding user response:
According to the Java Language Specification §8.1.6 the items of the permits
type list must be without their type parameters.
So, permits B<?>
is incorrect and has to be corrected to permits B
.
Please make sure that permits B<?>
does not give a compile error and permits B<?>
does give a B is a raw type. References to generic type B<T> should be parameterized
warning instead, has been reported to Eclipse JDT.