Does EL support overloaded methods?

I upgraded my Java EE web application to use newer PrimeFaces version and suddenly the call of an overloaded bean method in an action attribute of PrimeFaces commandlink did not work anymore. I tried to use JSF default commandlink to test it and this one did not work either.

The method signatures are as follows:

public void updateA(B b);
public void updateA(A a);

It always tried to cast A to B.

More curious, how could it work before the upgrade?


EL does not support it, no. It'll always be the first method of the Class#getMethods() array whose name (and amount of arguments) matches the EL method call. Whether it returns the same method everytime or not depends on the JVM make/version used. Perhaps you made a Java SE upgrade in the meanwhile as well. The javadoc even says this:

The elements in the array returned are not sorted and are not in any particular order.

You should not rely on unspecified behaviour. Give them a different name.


The way you can get around this is to create a generic method and do the 'routing' inside that method. I know that this might not be ideal, but you end up with less configurations in functions and XHTML pages.

if (A.class.isInstance(obj)) {
    A o = (A) obj;
    return method(o, highRes);
} else if (B.class.isInstance(obj)) {
    B o = (B) obj;
    return method(o, highRes);
} else if (C.class.isInstance(obj)) {
    C o = (C) obj;
    return method(o, highRes);
} else {
    throw new FacesException("Unsupported Conversion: " + obj);
}