How Evolution Harms a Programming Language

Home » How Evolution Harms a Programming Language » Random » How Evolution Harms a Programming Language

Java is a lovely programming language, but after its biggest evolutionary step (from 1.4 to 1.5) some awkward things started occurring, since the new compiler should be backwards compatible. Java programmers must recall about some backwards compatibility aspects in order to understand why the Java compiler acts in a somewhat strange way at times.

Method overloading, for example, became pretty tricky. Guess what’s the result for the program below…

[code language=’java’] public class MethodOverloading
{
void doSomething(Integer i)
{
System.out.println("Integer");
}

void doSomething(double d)
{
System.out.println("double");
}

public static void main(String[] args)
{
MethodOverloading mo = new MethodOverloading();

int i = 10;
mo.doSomething(i);
}
}
[/code]

Result: double (What the heck? Hã? Co to jest? Что это? ¿Qué es esto?)

Explanation: Prior to supporting autoboxing, Java has supported widening. Therefore, the compiler will choose widening over autoboxing, even if there’s a corresponding (Integer) method available.

Leave a Comment