I have the following class in a common bank:
public class Common
{
public Common(List list)
{
...
}
}
Then I change the constructor parameter from a Listto a Collectionas follows:
public class Common
{
public Common(Collection collection)
{
...
}
}
Restoring the common jar and starting the system calls NoSuchMethodErrorin any dependent class when it calls the constructor until I recompile this class.
I have a few ideas that cause this, according to how the constructor is related in the bytecode of the dependent class, but I'm not 100% sure.
Please, someone shed light on what is happening here?
Update
Subsequently, I did a quick test and looked at the bytecode:
Compiled from "Client.java"
public class Client extends java.lang.Object{
public Client();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: new #2; //class ArrayList
3: dup
4: invokespecial #3; //Method java/util/ArrayList."<init>":()V
7: astore_1
8: new #4; //class Common
11: dup
12: aload_1
13: invokespecial #5; //Method Common."<init>":(Ljava/util/List;)V
16: pop
17: return
}
As Tom said, and as you can see on line 13, the exact constructor is bound at compile time.
You will learn something new every day :-)