valhalla-dev Digest, Vol 7, Issue 66

Remi Forax forax at
Tue Jan 20 11:25:55 UTC 2015

On 01/20/2015 11:11 AM, Peter Levart wrote:
> On 01/20/2015 12:33 AM, Brian Goetz wrote:
>>> Multi-dimensional matching is not well-served by any loose or ambiguous
>>> matching, which is why I had specified a system not needing such.
>> Except that's exactly how method overload selection works in Java 
>> today [1]; by contrast, there are no left-to-right precedence 
>> mechanisms.  So while you might consider the left-to-right rule 
>> "better", when taken in the context of how the language already works 
>> (and how developers think), I think this has to be rejected.
>> [1] The lack of a meet rule actually causes problems here as well, 
>> such as overloads like foo(Object, String) vs foo(String, Object) 
>> (which do you call with foo("", "")?)
> Could the meet rule be added to overloads in Java? I mean only in the 
> form of a compile-time warning of course. It seems it could be useful 
> for API designers.

You can not do that because by design you don't know all the subtypes of 
a supertype in Java,
so by example, what is the meet rule for
   class Foo {
     void bar(Runnable r) { ... }
     void bar(Serializable s) { ... }

As an API designer, the best rule about overloads is to avoid them :)

> Peter


More information about the valhalla-dev mailing list