On 12/21/2009 07:31 PM, Asiri Rathnayake wrote:
Hi Thomas,
May be we
can avoid the enum type by using generics?
<T extends EntityReference> T getCurrentEntityReference();
Not sure if this is a good practice though.
Generic does not exist in the bytecode so impossible to know that you
want the EntityType.WIKI if you don't explicitly ask for it.
Right. Inside the method we'd have no clue what the client code is
requesting.
Would be cool if we can somehow not depend on the EntityReference
implementation type within the getCurrentEntityReference() method (thereby
not having to know which type the user wants but just cast and return what
is available). But I don't know if this is possible, and this would still
mean having to do an unsafe cast like:
EntityReference ref = ....;
return (T) ref;
which is also not that good.
private Map<Class<T>, T> currentReferences populated at the start of the
request;
public <T extends EntityReference> T getCurrentEntityReference(Class<T>
clazz) {
return currentReferences.get(clazz);
}
Could this work?
--
Sergiu Dumitriu
http://purl.org/net/sergiu/