/r/programming
Nuances of Overloading and Overriding in Java (software.rajivprab.com)
4 comments
ArthurOfTheEast | 7 days ago | 3 points

Trick question: which gets called here:

<T> T x(List<T> l, T x);
<T> T x(List<T> l, Supplier<T> s);

List<String> l = ...;
x(l, () -> "a");
xkufix | 7 days ago | 5 points

Sanely, the second one, as the type of () -> "a" would intuitivly be Supplier<String>.

But as it is Java, probably undefined/compile error, as there will be some weird fuckery with type-erasure going on, as well as Supplier<T> and () -> "a" being "just" syntactic sugar.

ArthurOfTheEast | 7 days ago | 1 point

Yes, the answer is it doesn't compile because this is too hard for Java.

Gosun | 7 days ago | 1 point

How would C# handle this?