Hi Sebastien,

I've verified that the code doesn't work with Oracle JDK as well.

I think the problem is in Java 8's static method in interface.
If you split IWidget into:

interface IWidget
{
   Behavior newBehavior(String name);
}

class Util {
   @SuppressWarnings("unchecked")
   static <T extends Behavior, W extends Component & IWidget> T
newBehavior(W widget)
   {
      return (T) widget.newBehavior("#" + widget.getName());
   }
}

Then it works correctly!

Maybe it is worthy to file a bug. Static method in a class works as
expected, but static method in an interface doesn't. The varargs are
the same.


Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Sun, Feb 21, 2016 at 11:33 PM, Sebastien <[email protected]> wrote:

> Hi devs,
>
> I come thought an issue with Java 8. Under certain conditions the compiler
> [1] bind to another method (an overload), and crash at runtime.
>
> The problem is demonstrated here:
> https://gist.github.com/sebfz1/6235c5545e7335985549
>
> You will easily recognize that Wicket has the same construction. There are
> workarounds from the user perspective, but I have no fix for Wicket to
> prevent this. For instance, such overload does not solve the issue:
>
> void add(Behavior behavior, Behavior... behaviors)
>
> I was thinking opening a bug to jvm vendors, but previous complains about
> varargs inference were solved as "not a bug".
>
> What are you thoughts?
>
> Thanks in advance,
> Sebastien.
>
> [1] openjdk, but seems to also be the case with oracle's jdk
>

Reply via email to