I am trying to find a generic type using Google's Guava TypeToken library. I am not able to find the actual calls to use with the correct parameters to extract the type I want.
public class BaseEntity { }
public class BaseResource { }
public class EntityService<E extends BaseEntity, R extends BaseResource> { }
public class TestEntity extends BaseEntity { }
public class TestResource extends BaseResource { }
public class TestEntityService extends EntityService<TestEntity, TestResource> { }
public class EntityRsqlPredicateBuilder<
S extends EntityService<E, R>,
E extends BaseEntity,
R extends BaseResource>
{
EntityRsqlPredicateBuilder() {
// I would like to get the the class type for E (i.e. TestEntity.class)
Class<E> entityClass = ???
}
}
// in code, use EntityRsqlPredicateBuilder
EntityRsqlPredicateBuilder<TestEntityService> = new EntityRsqlPredicateBuilder();
My backup strategy is just to pass the class into the EntityRsqlPredicateBuilder. However, this seems like code duplication when the type should already be known.
Appreciate any ideas on how to do this.