compilation error in maven but not in eclipse for self types

136 Views Asked by At

I'm trying to create some java SELF types

What is the reason for which

  1. everything compiles perfectly in eclipse
  2. maven compiles with the following error

    types Foo and FooLike are incompatible; both define existing(), but with unrelated return types

Details

Maven&Java version:
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: D:\home\raiser-apps\apps\maven\current\bin\..
Java version: 1.8.0_252, vendor: AdoptOpenJDK, runtime: D:\home\raiser-apps\apps\adopt8-hotspot\current\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Eclipse version:
Version: 2019-09 R (4.13.0) - Build id: 20190917-1200

The test

This compiles in eclipse but not in maven.

The interface Foo and Bar are part of the public API, FooLike is an internal.

package org.jedio;

import java.util.List;

public class CompilationBugTest {
  public interface Foo {
    <T extends Foo> List<T> existing();
  }

  public interface FooLike<SELF extends FooLike<SELF>> extends Foo {
    @SuppressWarnings("unchecked")
    // eclipse warning:
    // Type safety: The return type List<SELF> for existing() from the type CompilationBugTest.FooLike<SELF> needs
    // unchecked conversion to conform to List<CompilationBugTest.Foo> from the type CompilationBugTest.Foo
    @Override
    default List<SELF> existing() {
      throw new RuntimeException("Not implemented yet!!!");
    }
  }

  /**
   * - eclipse - Version: 2019-09 R (4.13.0) - Build id: 20190917-1200
   *   - no warning or error
   * - maven - using default 1.8 compiler, maven-compiler-plugin:3.8.1
   *   - error:types Foo and FooLike<Bar> are incompatible; both define existing(), but with unrelated return types
   */
  public interface Bar extends FooLike<Bar>, Foo {
  }
}

Update

Adding the following implementation to Bar will allow compilation in maven as well

@Override
default List<Bar> existing() {
  return FooLike.super.existing();
}
0

There are 0 best solutions below