FULL PRODUCT VERSION :
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.3.9600]
A DESCRIPTION OF THE PROBLEM :
javac incorrectly reports the cause of a compilation error in the included source. The source attempts to call a non-static method from a static context. This occurs when attempting to call a varargs method with an array of the varargs type.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Attempt to compile the included source.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Test.java:5: error: non-static method prints(int...) cannot be referenced from a static context
prints(ints);
^
1 error
ACTUAL -
Test.java:5: error: method prints in class Test cannot be applied to given types;
prints(ints);
^
required: int[]
found: int[]
reason: varargs mismatch; int[] cannot be converted to int
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Test {
public static void main(String[] args) {
int[] ints = new int[]{1, 2, 3, 4, 5};
prints(ints);
}
void prints(int... ints) {
for(int i : ints) {
System.out.println(i);
}
}
}
---------- END SOURCE ----------
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.3.9600]
A DESCRIPTION OF THE PROBLEM :
javac incorrectly reports the cause of a compilation error in the included source. The source attempts to call a non-static method from a static context. This occurs when attempting to call a varargs method with an array of the varargs type.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Attempt to compile the included source.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Test.java:5: error: non-static method prints(int...) cannot be referenced from a static context
prints(ints);
^
1 error
ACTUAL -
Test.java:5: error: method prints in class Test cannot be applied to given types;
prints(ints);
^
required: int[]
found: int[]
reason: varargs mismatch; int[] cannot be converted to int
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Test {
public static void main(String[] args) {
int[] ints = new int[]{1, 2, 3, 4, 5};
prints(ints);
}
void prints(int... ints) {
for(int i : ints) {
System.out.println(i);
}
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-8055514 Wrong, confusing error when non-static varargs referenced in static context
-
- Closed
-