-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathAmbiguousVarargsMethodOverloading.java
54 lines (50 loc) · 1.61 KB
/
AmbiguousVarargsMethodOverloading.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Test
{
void varargs(int...a)
{
System.out.println("METHOD:varargs(int...)\tNUMBER OF ARGUMENTS:"+a.length+"\tITEMS:");
for(int i:a)
{
System.out.println(i+" ");
}
}
void varargs(boolean...a) {
System.out.println("METHOD:varargs(boolean...)\tNUMBER OF ARGUMENTS:" + a.length + "\tITEMS:");
for(boolean i:a)
{
System.out.println(i+" ");
}
}
void varargs(String... a) {
System.out.println("METHOD:varargs(String...)\tNUMBER OF ARGUMENTS:" + a.length + "\tITEMS:");
for (String i:a)
{
System.out.println(i+" ");
}
}
void varargs(float... a) {
System.out.println("METHOD:varargs(float...)\tNUMBER OF ARGUMENTS:" + a.length + "\tITEMS:");
for(float i:a)
{
System.out.println(i+" ");
}
}
void varargs(String msg,int... a) {
System.out.println("METHOD:varargs(String,int...)\tNUMBER OF ARGUMENTS:" + a.length + "\tITEMS:"+msg +"\t");
for(int i:a)
{
System.out.println(i+" ");
}
}
}
class VarargsMethodOverloading {
public static void main(String[] args) {
Test obj=new Test();
obj.varargs("Hello World",10,30,80,90);
obj.varargs(10.9f,8.0f);
//obj.varargs(true,false);
//obj.varargs("Disha","Argha","World");
obj.varargs();//ambiguous
obj.varargs("A");//ambiguous.Compiler cannot resolve between varargs(String...) and varargs(String,int...)
}
}