overloading using an argument that was returned from a method with generic return type

Viewed 27

I have a Java overloading issue that I cannot understand.

The code is as follows:

private void f(Object o) {
}

private void f(Collection c) {
}

private <T> T dummy() {
    return null;
}

private void g() {
    f(dummy());
}

Now, dummy() returns an object of an undefined type so erasure should lead to a type of Object. However, the invocation f(dummy()) actually calls f(Collection) and not f(Object). Why is this the case?

0 Answers
Related