Method and Constructor Overloading Best Practices in Java

You need to be careful while overloading a method in Java, especially after the introduction of autoboxing in Java 5. Poorly overloaded method not only adds confusion among developers who use that but also they are error prone and leaves your program on compiler's mercy to select proper method. One of the best examples of a poorly overloaded method is the remove method of ArrayList. There are two versions of remove, first, one which takes an Object as argument i.e. remove(Object element) and the second one, which takes an index as argument i.e. remove(int index). It worked fine until Java 1.4 where there is clearly a distinction between primitive types and objects type but in Java 1.5, where you can pass an int primitive to a method which accepts an Integer object, creates some nasty problem.
Read more �

Comments

Popular posts from this blog

Cara Membuat Halaman Login Hotspot Berbeda pada 1 Mikrotik

UltraISO Premium Edition v9.5.3

Arti OSAKMJ