I have a few procedures that, for simplicity's sake, look like the following:
public String fetchValueAsString(String key);
public DateTime fetchValueAsDateTime(String key);
I want something like
public <X is a String or a DateTime> X fetchValue(String key); // pseudo-code
that I could call like this (without casting; the type is implied by the passed parameters):
String str = fetchValue("subject");
DateTime dt = fetchValue("startDate");
I know I could just have one method that returns the Object type and just do a casting conversion, but I'm wondering if there is a way I can have just one method called, and somehow use generics to determine the return value. So, is it possible in Java (it is in C#)?