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 :-(

Comments

Add a New Comment
myface.jpg
Find me on:
LiveJournal Facebook MySpace Twitter reddit Google Amazon.comBoardGameGeek
{"module":"feed\/FeedModule","params":{"src":"http:\/\/twitter.com\/statuses\/user_timeline\/18552685.rss","limit":"1","module_body":"[http:\/\/twitter.com\/psyllogism %%description%%]"}}

psyche (sī'kē) n. 1. That which is responsible for one's thoughts and feelings. 2. The seat of the faculty of reason.

syllogism (sĭl'ō-jĭz'əm) n. 1. Reasoning from the general to the specific. 2. A subtle or specious piece of reasoning.

psyllogism (sī'lō-jĭz'əm) person: A twenty-something college graduate, part time grad student, software developer, and geek. I am married and trying to manage school, life, friends, family, a job, and an (un)healthy gaming hobby.

(view template)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License