Re: Can this callback mechanism be generified?
Mark Space wrote:
This I still don't get. What's the advantage of Class<?> over Class?
I like your original program better. All the random generics are just
starting to obscure the actual design now.
I understand what you mean, but if you view it from a consumers (of the
API) point of view, I think it makes sense. I went from the old Java 1.0
way:
installCallback( Date.class, new Callback(){
public String format(Object obj)
{
Date date = (Date)obj;
return SimpleDateFormat.getInstance().format(date);
}
});
....to this, where the type of my callback definition flows over to
become the argument of the callback (thanks again Daniel) and gives me
more type-safety and allows NetBeans to create the anonymous inner class
with no need of casting:
installCallback( Date.class, new Callback<Date>(){
public String format(Date date) {
return SimpleDateFormat.getInstance().format(date);
}
});
....to the final version, where the type of my callback is extracted
rather than having to be supplied explicitly:
installCallback( new Callback<Date>(){
public String format(Date date) {
return SimpleDateFormat.getInstance().format(date);
}
});
Without closures, I think that's as clean as I can get it. Only rough
edge appears to be the way I extract the type from Callback.
/Casper