valhalla-dev Digest, Vol 7, Issue 26
Thomas W
twhitmore.nz at gmail.com
Thu Jan 8 00:24:15 UTC 2015
Hi Vitaly, good questions.
Luckily there are good answers :)
> So say I'm authoring a generic class and call System.out.println() - how
do I know which method is going to be called?
The most specific one, matching the specialized type of your 'any T'
parameter.
> Suppose println returned different types depending on overload - what's
my return value type? I can't target type it because that implies I know
what the generic type will be and I don't, I'm just shipping a generic
library.
Since we're conservative, we should only consider methods having a
return-type/ signature consistent with the "base" method. This means we
look at the signature of PrintStream.print(Object arg) and only consider
methods consistent with that. I think that would work fine, and be both
conservative & reliable.
Would that work for you?
I did see that Brian suggested some kind of explicit enhancement of
existing libraries.. not sure if that's a "print(any T)" method, or if so,
how it would actually implement/ or despatch efficiently.
Regards,
Thomas
More information about the valhalla-dev
mailing list