Ambiguous call to Module
Asked Answered
T

1

6

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.

Threnody answered 24/4, 2019 at 15:6 Comment(1)
The JDK 9 release notes has a section on source compatibility issues that deals specifically with this one, see: oracle.com/technetwork/java/javase/…Acquit
S
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;
Suffragan answered 24/4, 2019 at 16:15 Comment(2)
Or just use an explicit import com.module.Module; instead of import com.module.*;Correggio
@Correggio Indeed, that's what Alan's shared link suggests as well. Should update the answer with that I believe. Thanks.Suffragan

© 2022 - 2024 — McMap. All rights reserved.