package work8; public class myTest { public static void main(String[] args) { //有直接匹配的 //加宽后匹配的 //包装后匹配的 //加宽后再包装匹配的 //可变元参数列表的 TestOverload test=new TestOverload(); /* short s=5; test.go(s);*/ short s1 = 5; short s2 = 6; test.go(s1,s2); //int int } }
package work8; public class TestOverload { /* void go(int x) { System.out.println("int"); } void go(short x) { System.out.println("short"); } void go (Short x) { System.out.println("Short"); } void go(Integer x) { System.out.println("Integer"); } */ void go(int x, int y){ System.out.println("int,int"); } void go(short ...x){ System.out.println("short…"); } void go(Short x, Short y){ System.out.println("Short,Short"); } }