Accessing entity IDs generically
I'm writing an abstract class that will be parameterised with a Roo entity type T. A method in my class needs access to that entity's ID. For example:
Code:
public abstract class EntityProcessor<T> {
public void process(T entity) {
Long id = entity.getId(); // compile error; T is an Object
}
}
The problem is that Roo entities don't seem to implement any interface that has a "getId()" method.
I can work around this by creating my own "Identified" interface with a "Long getId()" method, and applying that interface manually to all my Roo domain types, but I was wondering if there was a better solution, e.g. using some special generics trickery or an existing interface that has a getId() method.
Andrew Swan
"Now is the EJB of our discontent made glorious Spring"