Hi Pedro,
Your proposal will not work because Java does not resolve functional
interfaces to subtypes of the target type. For example, take the Label
constructor:
public Label(String id, IModel<?> model)
I would like to use this constructor as follows:
new Label("id", Math::random)
In Wicket 8 this works, because IModel is a functional interface, so Java
knows how to convert a method taking no arguments and returning a double into
a IModel<Double> by mapping that method to getObject().
With your proposal, this code needs to be changed to:
new Label("id", (IReadOnlyModel<Double>) Math::random)
So time ago, we tried to make IModel extend a ReadOnlyModel. In that case, it
would work, but the change did not work out very well.
Best regards,
Emond
On vrijdag 7 april 2017 12:45:53 CEST Pedro Santos wrote:
> Hi devs,
>
> IModel isn't an interface designed to provide a function, it's rather an
> interface designed to provide and manipulate (setObject and detach methods)
> internal state.
>
> IMO a better alternative to benefit from Java 8 features would be to move
> the FunctionalInterface annotation to an interface that actually is
> designed to provide one function.
>
> I propose that we add a new interface extending IModel to provide this
> functional interface, instead of to misplace it in an interface made for
> objects with internal state.
>
> e.g.
>
> @FunctionalInterface
> interface IReadyOnlyModel / IModelFunction / IFunction extends from IModel{
>
> default void setObject(final T object)
> {
> throw new UnsupportedOperationException("unsuported");
> }
>
> default void detach()
> {
> throw new UnsupportedOperationException("unsuported");
> }
>
> }
>
> Cheers
>
> Pedro Santos