Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous call to Module

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.

like image 322
AKJ Avatar asked Apr 24 '19 15:04

AKJ


People also ask

Why am I getting an ambiguous call between methods or properties error?

C# Error: The call is ambiguous between the following methods or properties. Basically, try uninstalling the unnecessary NuGet packages that you might have installed and you are not actually using them.

What is ambiguity in C++?

In C++, the type of argument that is used to call the function is converted into the type of parameters defined by the function. Let’s understand ambiguity through a few examples. Below is the C++ program to demonstrate the ambiguity. prog.cpp:25:11: error: call of overloaded ‘test (char)’ is ambiguous

What does error call of overloaded test (float) is ambiguous mean?

prog.cpp:25:12: error: call of overloaded ‘test (float)’ is ambiguous The above code will throw an error because the test (2.5f) function call will look for float function if not present it is only promoted to double, but there is no function definition with double or float type of parameter.

What is ambiguity in function overloading?

In Function overloading, sometimes a situation can occur when the compiler is unable to choose between two correctly overloaded functions. This situation is said to be ambiguous. Ambiguous statements are error-generating statements and the programs containing ambiguity will not compile. Automatic type conversions are the main cause of ambiguity.


Video Answer


1 Answers

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;
like image 111
Naman Avatar answered Sep 22 '22 17:09

Naman