Reputation: 3
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
Upvotes: 0
Views: 68
Reputation: 1175
You can use the following code:
static <E> E yourMethod(){
AbsEntity absEntity = new AbsEntity();
return (E)absEntity;
}
Upvotes: 0
Reputation: 6721
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!
Upvotes: 0
Reputation: 18923
Something like this:
public <E extends AbsEntity> E yourMethod() {
//yourObject
return yourObject;
}
Upvotes: 1