On Thu, Jun 9, 2011 at 1:11 PM, Attila Szegedi <[email protected]> wrote:

> The question however is whether these solutions we perceive as intuitive
> can indeed be formally valid under some set of consistent rules, without
> running into a contradiction.
>

In answer to you and Neal, it seems there's a simple way to improve the spec
to provide the "intuitive" result (or at least the result most people here
seem to find intuitive: treat primitives as more specific than Object (and
potentially over boxed numeric types as well). My (mis)interpretation of the
Java spec for Mirah's compiler works this way currently; primitives are
given priority over reference types unconditionally, since the alternative
*requires* a boxing conversion. If you have to walk through a conversion to
get there, you're walking into a less-specific signature.

Walking back through phase 3 and specificity (and I apologize for the
informality of this..I'm not a spec writer):

Given:

void foo(String, int, Object...)
void foo(String, Object...)
foo("bar", 1) or foo("bar", 1, "baz")

* phase three is selected because only varargs can apply
* the second signature is only valid for the given arguments with a method
invocation conversion of int => Integer
* Integer is a subclass of Object, so we arrive at the ambiguity from before
* ...BUT...primitive is always more specific than reference, and so the int
method is chosen

I know many folks hate the special treatment of primitives in Java, but this
sort of exception is nothing new. Yes, primitives and reference types live
in different worlds and do not share a hierarchy. I would argue that their
disjointedness explicitly makes the strict subtype specificity check
invalid; subtyping has no meaning to primitives, so you're measuring
specificity of an int parameter with an invalid metric. It would be like
measuring the specificity of Integer versus Long based on their bit sizes
and bit-level widening conversions. Since that doesn't make sense, neither
does forcing subtype-driven specificity constraints on primitive types.

- Charlie

-- 
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en.

Reply via email to