java overloaded method
- by Sean Nguyen
Hi,
I have an abstract template method:
class abstract MyTemplate
{
public void something(Object obj)
{
doSomething(obj)
}
protected void doSomething(Object obj);
}
class MyImpl extends MyTemplate
{
protected void doSomething(Object obj)
{
System.out.println("i am dealing with generic object");
}
protected void doSomething(String str)
{
System.out.println("I am dealing with string");
}
}
public static void main(String[] args)
{
MyImpl impl = new MyImpl();
impl.something("abc"); // --> this return "i am dealing with generic object"
}
How can I print "I am dealing with string" w/o using instanceof in doSomething(Object obj)?
Thanks,