| Summary: | Eclipse compiler can determine correct varargs method while javac complains method ambiguous | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Martin Fabricius <SirMadjosz+eclipse> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED MOVED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | ||
| Version: | 4.23 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 10 | ||
| Whiteboard: | |||
Consider the following MWE public class NonAmbiguousVarargs { static void method(int... array) { System.out.println("int array"); } static <T> void method(T... array) { System.out.println("Object array"); } public static void main(String[] args) { method(1); } } While eclipsec compiles this code without problems, bindind the call to method to the (int...) overload, javac fails with the following error message NonAmbiguousVarargs.java:12: error: reference to method is ambiguous method(1); ^ both method method(int...) in NonAmbiguousVarargs and method <T>method(T...) in NonAmbiguousVarargs match where T is a type-variable: T extends Object declared in method <T>method(T...) 1 error Assuming the behaviour of the javac is correct according to the Java language specification (the code does only compile in JDK 1.5 and 1.6; JDK 1.7 - 18 give the above error) then eclipsec should also give an error on this line. Tested with Eclipse SDK Version: 2022-03 (4.23) Build id: I20220126-1800 java version "1.5.0_22" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03) Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_22-b03, mixed mode) java version "1.6.0_45" Java(TM) SE Runtime Environment (build 1.6.0_45-b06) Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode) openjdk version "1.7.0_75" OpenJDK Runtime Environment (build 1.7.0_75-b13) OpenJDK Client VM (build 24.75-b04, mixed mode) ... some other versions in between ... openjdk 18-ea 2022-03-15 OpenJDK Runtime Environment (build 18-ea+23-1525) OpenJDK 64-Bit Server VM (build 18-ea+23-1525, mixed mode, sharing)