0

I am new to java i have a set of classes which extends AbsEntity class.I have a abstract method which should return a Class object and that Class object should be E extends AbsEntity type...here is how i am trying to declare

abstract Class<E externds AbsEntity> E getAbsEntity();

This declaration through me error Actually i dont know hw to declare...A method whos return type should be Class type which is E extends AbsEntity Plz help

3 Answers3

1

Something like this:

public <E extends AbsEntity> E yourMethod() {
    //yourObject
    return yourObject;
}
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
0

It should be declared before the return type, like so:

    abstract <E extends AbsEntity> Class<E> getAbsEntity();

Take a Look here at Oracle docs.

Hope this helps!

anacron
  • 6,443
  • 2
  • 26
  • 31
0

You can use the following code:

static <E> E yourMethod(){
    AbsEntity absEntity = new AbsEntity();
    return (E)absEntity;
}
Pang
  • 9,564
  • 146
  • 81
  • 122
flopcoder
  • 1,195
  • 12
  • 25