08/03/16 21:58:36
>>503
> void test(Hoge2 a, Hoge3 b){}
> void test(Hoge a, Hoge3 b){}
Hoge2 a は Hoge a に代入可能。 Hoge3 a は Hoge3 b に代入可能。
以上により、前者の引数は全て後者の引数に代入可能。
なので、前者は後者より特殊なメソッド(specific method)と言われる。
この特殊なメソッドが一つに決まる場合は、
それが最も特殊なメソッド(most specific method)と言われて、それが呼び出される。
> void test(Hoge a, Hoge3 b){}
> void test(Hoge2 a, Hoge2 b){}
みたいに一つに決まらない場合は曖昧となってコンパイルエラーになる。
詳しくはこの辺呼んでくれ。
15.12.2.5 Choosing the Most Specific Method
URLリンク(java.sun.com)
15.12.2.2 最も特殊なメソッドの選択
URLリンク(www.y-adagio.com)