Error occurs when I am ready to pass a function in MyInterface
Â
Hello experts,
I have MyInterface with 2 classes A and B, which is implementing MyInterface.
Then I stated 2 objects:Â 1. MyInterface a = new A (), 2. MyInterface b = new B ().
When I am ready to pass a function – function doSomething(A a){}, the following error occurs:
This is my code:
public interface MyInterface {}
public class A implements MyInterface{}
public class B implements MyInterface{}
public class Tester {
  public static void main(String[] args){
    MyInterface a = new A();
    MyInterface b = new B();
    test(b);
  }
  public static void test(A a){
    System.out.println("A");
  }
  public static void test(B b){
    System.out.println("B");
  }
}
My issue is that I am receiving from a few component interfaces which may be in all types of classes. Also, I want to write function for every class.
I need to solve this error. I need your help.
Please give me a solution.
Thanks.