3

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?

mrkernelpanic
  • 4,268
  • 4
  • 28
  • 52

1 Answers1

9

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.

Jeroen Steenbeeke
  • 3,884
  • 5
  • 17
  • 26
  • You are absolutely correct. That fixed it, but why does it only happen in Wicket 8? – mrkernelpanic Aug 21 '18 at 07:07
  • `IGenericComponent` did not define `setDefaultModel` in Wicket 7 – Jeroen Steenbeeke Aug 21 '18 at 07:08
  • There is something wrong with this opening sentence "This error occurs when you do not give AjaxLink a generic type. The error occurs when you do:" One of these has to be negative case, they are both saying the error occurs regardless of whether T provided. – BodhiOne Jul 23 '20 at 13:19
  • The code sample is supposed to be part of the second sentence, in which case they both describe the same case, but I'll edit the answer to clarify – Jeroen Steenbeeke Jul 23 '20 at 18:19