File tree Expand file tree Collapse file tree 3 files changed +24
-0
lines changed
tests/net.sf.j2s.test.junit/src/net/sf/j2s/test/junit Expand file tree Collapse file tree 3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ public static Test suite() {
2424 suite .addTestSuite (OverloadTest .class );
2525 suite .addTestSuite (SubclassTest .class );
2626 suite .addTestSuite (ThisTest .class );
27+ suite .addTestSuite (VarArgsTest .class );
2728
2829 return suite ;
2930 }
Original file line number Diff line number Diff line change @@ -45,6 +45,15 @@ public void testVarArgsNotEmpty() {
4545 assertEquals ("ints: 4 7 9 " , s );
4646 }
4747
48+ /**
49+ * Call a varArgs method with some "float" arguments, to check if
50+ * the correct overload ("float ..." vs. "int ...") is selected.
51+ */
52+ public void testVarArgsNotEmpty_WithFloat () {
53+ String s = new CVarArgs ().fVarArgsInt (4.0f ,7 ,9 );
54+ assertEquals ("floats: 4.0 7.0 9.0 " , s );
55+ }
56+
4857 /**
4958 * Call a varArgs method with some arguments (via array).
5059 */
Original file line number Diff line number Diff line change @@ -9,6 +9,20 @@ public String fVarArgsInt(int... ns) {
99 return result ;
1010 }
1111
12+ /**
13+ * Attention: DON'T change the "misleading" method name (e.g. to "<code>fVarArgsFloat</code>").
14+ *
15+ * <p> This method is used to check for ambiguity resolution of methods with same name and
16+ * different var args types (<code>int...</code> vs <code>float...</code>)
17+ */
18+ public String fVarArgsInt (float ... ns ) {
19+ String result = "floats: " ;
20+ for (int i = 0 ; i < ns .length ; i ++) {
21+ result += ns [i ] + " " ;
22+ }
23+ return result ;
24+ }
25+
1226 public String fStringVarArgsInt (String s , int ... ns ) {
1327 String result = s ;
1428 for (int i = 0 ; i < ns .length ; i ++) {
You can’t perform that action at this time.
0 commit comments