I'm sure this is elementary, but I am stumped. The example is grossly over-simplified but boils down to the following. I have some overloaded methods in a class like so:
public void build(MyImplOneOfAnInterface item); public void build(MyImplTwoOfAnInterface item); I then have another method that does the following:
public void buildIt(MyInterface item) { build(item); } When I attempt to compile, I get the following error:
cannot find symbol
This is because the JVM cannot determine the implementation of the interface at compile time so that it knows which overloaded method to call.
How can this be decided at runtime? It seems like the JVM ought to be able to figure this out.
PS: I don't want to define a method that takes the interface as the argument and then does a bunch of if/else statements using instanceof operators.