How JVM finds method (parameter with the closest matching) to call in case of function overloading

后端 未结 6 1574
耶瑟儿~
耶瑟儿~ 2020-12-15 22:56

The JVM decides which overloaded method to call at compile time. I have one example:

public class MainClass{

  public static void go(Long n) {System.out.pr         


        
6条回答
  •  温柔的废话
    2020-12-15 23:33

    Java looks for the closest match first. It tries to find the following:

    1. Exact match by type
    2. Matching a super class type
    3. Converting to a larger primitive type
    4. Converting to an auto boxed type
    5. Varargs

提交回复
热议问题