5

I am trying to recompile a JAVA8 code in JAVA11. Getting below compilation errors.

error: reference to Module is ambiguous private Module module; both interface com.module.Module in com.module and class java.lang.Module in java.lang match

Being new to the Java not able to fully understand the root cause. Any information will be of great help.

Naman
  • 27,789
  • 26
  • 218
  • 353
AKJ
  • 65
  • 1
  • 6
  • 3
    The JDK 9 release notes has a section on source compatibility issues that deals specifically with this one, see: https://www.oracle.com/technetwork/java/javase/9-relnote-issues-3704069.html – Alan Bateman Apr 24 '19 at 19:34

1 Answers1

8

both interface com.module.Module in com.module and class java.lang.Module in java.lang match

The error is mostly because of the new class java.lang.Module introduced in Java-9.

Just use the fully qualified name while referencing the interface/class that you've defined as:

private com.module.Module module;

Alternatively, as pointed out by Alan and Holger in comments and from the release notes of Java-9, you can explicitly specify the import for your Module class as :

import com.module.Module;
Naman
  • 27,789
  • 26
  • 218
  • 353
  • 2
    Or just use an explicit `import com.module.Module;` instead of `import com.module.*;`… – Holger Apr 25 '19 at 09:44
  • @Holger Indeed, that's what Alan's shared link suggests as well. Should update the answer with that I believe. Thanks. – Naman Apr 25 '19 at 09:45