Java overloading rules

前端 未结 2 436
甜味超标
甜味超标 2020-11-30 07:17

I came across two overloading questions recently that I can\'t find an answer for and don\'t have a java environment to run some test code. I\'m hoping someone can help me b

2条回答
  •  失恋的感觉
    2020-11-30 07:39

    First question:

    Your assumption is correct. The second call to f() will call the varargs method. You can get the compiler to call the second method with:

    private void f(int a) {
        f(a, null);
    }
    

    Second question:

    Yes. However, you can't extend an interface. If you change A to an abstract class, things will compile.

提交回复
热议问题