Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Trying to understand the need for typecasting

843793Aug 26 2010 — edited Aug 26 2010
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();
    }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 23 2010
Added on Aug 26 2010
2 comments
1,603 views