I have not used this Play platform, so I'm not sure about the details here, but usually when you do what you want to do in Java, you just specify a specific class as a parameter for the static method. Of course, this is ugly, but it is Java.
I assume that this find method is a static method that is somehow (via annotation processing) added to this structure on each expanding class, right? In this case, I think your only way out is to do something like this:
public static <T extends TemporalModel> T getLatest(Class<T> cl) { try { return(cl.cast(cl.getMethod("find", String.class).invoke("order by created").first())); } catch(AllThosePeskyReflectionExceptions e) { throw(new Error(e)); } }
I think the best way available in view of the premises. I know this is ugly, so I would be happy to be wrong. :)
source share