Java Overload method with inherited interface

前端 未结 3 889
悲&欢浪女
悲&欢浪女 2021-01-13 13:53

i\'m trying to understand java behaviour. Using this interfaces :

public interface IA {}
public interface IB extends IA {}
public class myClass implements IB         


        
3条回答
  •  北恋
    北恋 (楼主)
    2021-01-13 14:14

    Because the compiler only knows that a is an instance of IA. Overloads are determined at compile time based on the compile-time types of the expressions involved, and the compile-time type of a is IA.

    (Compare this with overriding, where the method implementation is chosen at execution time based on the actual type involved.)

提交回复
热议问题