本帖最后由 long 于 2013-5-10 00:45 编辑
OverloadingVarargs2.java无法通过编译,但OverloadingVarargs3.java却顺利通过编译。这是为什么?- //: initialization/OverloadingVarargs2.java
- // {CompileTimeError} (Won't compile)
- public class OverloadingVarargs2 {
- static void f(float i, Character... args) {
- System.out.println("first");
- }
- static void f(Character... args) {
- System.out.print("second");
- }
- public static void main(String[] args) {
- f(1, 'a');
- f('a', 'b');
- }
- } ///:~
- //: initialization/OverloadingVarargs3.java
- public class OverloadingVarargs3 {
- static void f(float i, Character... args) {
- System.out.println("first");
- }
- static void f(char c, Character... args) {
- System.out.println("second");
- }
- public static void main(String[] args) {
- f(1, 'a');
- f('a', 'b');
- }
- } /* Output:
- first
- second
- *///:~
复制代码 |