java inheritance

Given these classes:

class Father {
  public Father getMe() {
    return this;
  }
}

class Child extends Father { .. }

I'm calling the public method of the Father class from the Child class:

Child c = new Child();
Child c1 = c.getMe();

So, this is not working, i have to use a cast to make it work :

Child c1 = (Child) c.getMe();

The question is: is there a better way to make it work without the cast? can be like this ?? :

public <T extends Father> T getMe() {
  return this;
}

Thanks in advance.

5
задан Seby 24 March 2011 в 14:16
поделиться