RI update: division of bridging responsibility between VM and compiler
Dan Smith
daniel.smith at oracle.com
Thu May 9 07:07:41 PDT 2013
On May 9, 2013, at 6:25 AM, Remi Forax <forax at univ-mlv.fr> wrote:
> I more worry about existing third party libraries that uses already existing interfaces like List or Map
> because these libraries may need to be re-compiled.
> I agree that they need to be recompiled only in a corner case,
> the third party library need to extends an already existing interface and have a public method
> with a name and parameter types that make the method an override of a default method listed below,
> but this corner case will appear.
>
> java/util/concurrent/ConcurrentMap default getOrDefault(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
> java/util/Comparator default reverseOrder()Ljava/util/Comparator;
> java/util/Comparator default thenComparing(Ljava/util/Comparator;)Ljava/util/Comparator;
> java/util/Map default getOrDefault(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
> java/util/Map default putIfAbsent(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
> java/util/Map default replace(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Z
> java/util/Map default replace(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
>
> By example, a comparator defined like this will cause trouble:
> public class FooComparator extends Comparator<Foo> {
> public FooComparator reverseOrder() { ... }
> }
>
> this code must be be recompiled because javac need to insert a bridge.
>
> That said, a note about this in the compatibility issues guide of the jdk8 is enough in my opinion.
But keep in mind: you're anticipating a scenario in which the client's method already existed _before_ the default methods were added, and it's only a coincidence that they happen to share the same name and have a compatible signature/return (but different erased signature/return). As you say, a corner case, but I want to emphasize how rare this should be.
Even then: the failure mode is to simply use the default method instead of the specialized method. Within the obscure space we're talking about, what are the chances that the default method doesn't already do the same thing as the specialized method?
Agreed that the release notes should mention the fact that new default methods in the API may share a name with methods that already exist in client code, and describe potential consequences.
—Dan
More information about the lambda-spec-experts
mailing list