Method Overloading

This is annoying. Given the following Java code snippet:

public class Overloading {
 
    public void foo(Object object) {
        System.out.println("I'm an object!");
    }
 
    public void foo(String string) {
        System.out.println("I'm a string!");
    }
 
    public void foo(List<?> list) {
        System.out.println("I'm a list!");
    }
 
    public static void main(String... args) {
        Overloading overlord = new Overloading();
 
        Object str = "Hello, world!";
        overlord.foo(str);
 
        Object lst = new ArrayList();
        overlord.foo(lst);
    }
}

When I run it, it gives me the following output:

> java Overloading
I'm an object!
I'm an object!

That's not what I want Method Overloading to do :-(

page_revision: 4, last_edited: 1251909429|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License