2 Replies Latest reply on Aug 26, 2010 2:03 PM by 843793

    Trying to understand the need for typecasting

    843793
      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();
          }
      }