前言:对于形参是基本类型或包装类型而已,方法的重载会优先选择基本类型。
如下代码所示:
=======================BaseType============================
public class BaseType
{
public void f(long index)
{
System.out.println("基本类型的方法被调用");
}
public void f(Long index)
{
System.out.println("包装类型的方法被调用");
}
public static void main(String[] args)
throws Exception
{
BaseType baseType = new BaseType();
int index = 140;
long index2 = 140L;
baseType.f(index2);
baseType.f(index);
baseType.f(Integer.valueOf(index));
}
}
执行结果:
基本类型的方法被调用
基本类型的方法被调用
基本类型的方法被调用
=====================OneNumber2EightBit=======================
public class OneNumber2Ei