wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Eugelink <t...@tbee.org>
Subject generics
Date Wed, 02 May 2012 10:02:58 GMT
I would like to suggest an API improvement in the fluent interface, which should not break
backwards compatibility. Currently if you create, say, a mandatory FileUploadField, you cannot
do this.

/FileUploadField lFileUploadField = new FileUploadField("fileInput", ...).setRequired(true);
/
Because setRequired is actually implemented in FormComponent and returns a FormComponent.
By adding the component type to the generics of FormComponent and casting the return value,
this could be resolved.

/public abstract class FormComponent<T, C>/
/{
     public C setRequired(boolean required)
     {
         ...
         return (C)this;
     }
}
/
/public class FileUploadField extends FormComponent<List<FileUpload>, FileUploadField>/
/{
     ...
}

/Now the setRequired method in FormComponent knows exactly what type to return. The casting
naturally does not earn a style award, but the improvement in the API does, and in my opinion
is worth the trade-off.

Tom


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message