This discussion is archived
2 Replies Latest reply: Aug 26, 2010 7:03 AM by 843793 RSS

Trying to understand the need for typecasting

843793 Newbie
Currently Being Moderated
Can someone explain why there is a need to typecast in the getObject() method? Thank you,
public abstract class GenericTest<T extends GenericTest>
{
    public GenericTest()
    {
    }

    public void getObject()
    {
        T objectOne = getObjectCast();
        T objectTwo = (T) objectOne.getObjectCast();  //why must I typecast here?
    }

    public T getObjectCast()
    {
        return ( T ) new Object();
    }
}