maurizio.cimadamore at oracle.com
Mon Jul 15 09:25:42 PDT 2013
On 15/07/13 17:15, Zhong Yu wrote:
> Auto unboxing is evil all around. I config my IDE to mark it as error.
Problem is, if you can't look at the lambda, how do you tell if there's
boxing? You only know that two methods are applicable, one that requires
a lambda that returns an int, another requiring a lambda that returns a
reference - it would be premature to pick the first over the second, as
you still don't know what the lambda does.
> Do we really need auto unboxing in type inference? It seems like a fringe case.
> On Mon, Jul 15, 2013 at 11:09 AM, Maurizio Cimadamore
> <maurizio.cimadamore at oracle.com> wrote:
>> On 15/07/13 16:53, Marc Petit-Huguenin wrote:
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA256
>>> I am trying to use a comparator on a Map.Entry<String, Integer> stream, and I
>>> am not sure why this does not compile:
>> This is as expected - the method reference Map.Entry is defined on a
>> generic class with unknown parameter types (some Map<K, V>) - therefore
>> the compiler needs the info from the target (in a top-down way) in order
>> to decide what the method reference looks like. But the target type info
>> is incomplete as it depends on inference variables on its own.
>> So the compiler ends up applying a simpler (arity-based only) check
>> during overload resolution - which means the compiler can't really pick
>> the right comparing() method ahead of the target-type.
>> A shorter way to get this to compile should be this:
>> .sorted(Comparator.comparing(Map.Entry<String, Integer>::getValue))
>> Let me know if that works for you.
>>> error: reference to comparing is ambiguous
>>> error: incompatible types: Cannot instantiate inference variables T because of
>>> an inference loop
>>> (interestingly the second error was not present when using a build from last week)
>>> These two compile:
>>> .sorted(Comparator.comparing((Map.Entry<String, Integer> entry) ->
>>> - --
>>> Marc Petit-Huguenin
>>> Email: marc at petit-huguenin.org
>>> Blog: http://blog.marc.petit-huguenin.org
>>> Profile: http://www.linkedin.com/in/petithug
>>> -----BEGIN PGP SIGNATURE-----
>>> Version: GnuPG v1.4.12 (GNU/Linux)
>>> -----END PGP SIGNATURE-----
More information about the lambda-dev