Java Overload method with inherited interface

inheritance, interface, java, overloading

Solution

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.)

Problem

i'm trying to understand java behaviour. Using this interfaces : ``` public interface IA {} public interface IB extends IA {} public class myClass implements IB {} ``` I'm overloading a method like this : ``` public void method(IA a); public void method(IB b); ``` When calling method with the following object : ``` IA a = new myClass(); method(a); ``` Why does java use : ``` public void method(IA a); ``` instead of ``` public void method(IB b); ``` ? Thanks

Original source

Related problems