-
Selection among overloaded methods is static, i.e. the choice which overloading to invoke is made at compile time.
-
Avoid exporting two overloadings with the same number of parameters.
- e.g.
writeInt(int)andwriteDouble(double)better thanwrite(int)andwrite(double)
- e.g.
-
Do not export two overloadings with parameters that are not "radically different", i.e. parameters that can be cast to each other, in the same position.
- e.g. the overloadings
List.remove(Object)andList.remove(int)are problematic because forList<Integer> landint i,l.remove(Integer.valueOf(i))invokes the former whereasl.remove(i)invokes the latter.
- e.g. the overloadings
-
Do not overload methods to take different functional interfaces in the same argument position.
- e.g. For
ExecutorService exec,exec.submit(System.out::println)won't compile because there are two overloadingssubmit(Runnable)andsubmit(Callable), andSystem.out.printlnis also overloaded.
- e.g. For