javawicketwicket-8

Wicket 8 wicket setDefaultModel clashes with setDefaultModel


After upgrading from Wicket 7 to Wicket 8, I encounterd multiple erasure warnings in IntelliJ.

E.g. when using AjaxLink IntelliJ complains

'setDefaultModel(IModel model)' in 'org.apache.wicket.MarkupContainer' clashes with 'setDefaultModel(IModel model)' in 'org.apache.wicket.IGenericComponent'; both methods have same erasure yet neither overrides the other

Is there anything I can do about it?


Solution

  • This error occurs when you do not give AjaxLink a generic type. For example:

    new AjaxLink("id")
    

    Instead of something like:

    new AjaxLink<Void>("id")
    

    AjaxLink has the following definition:

    public abstract class AjaxLink<T> extends AbstractLink implements IAjaxLink, IGenericComponent<T, AjaxLink<T>>
    

    The ancestor class is MarkupContainer, which defines:

    public MarkupContainer setDefaultModel(final IModel<?> model)
    

    And it implements IGenericComponent, which has generic types <T, C extends IGenericComponent<? super T, ?>> which are assigned the types <T,AjaxLink<T>> and defines the method:

    Component setDefaultModel(IModel<?> model);
    

    Now, I'm not entirely sure if I fully understand the problem, but somehow due to the lack of generic types, the compiler cannot figure out that the implementation from MarkupContainer (which returns MarkupContainer) is covariant with the method defined in IGenericComponent.