You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Sven Meier (JIRA)" <ji...@apache.org> on 2016/07/21 07:58:20 UTC
[jira] [Comment Edited] (WICKET-5866) Reconsider generics of
IConverterLocator#getConverter()
[ https://issues.apache.org/jira/browse/WICKET-5866?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15385697#comment-15385697 ]
Sven Meier edited comment on WICKET-5866 at 7/21/16 7:57 AM:
-------------------------------------------------------------
We could ease the pain with a new factory method on Component:
{code}
/**
* Get the converter that should be used by this component, delegates to
* {@link #createConverter(Class)} and then to the applications
* {@link IConverterLocator}.
*
* @param type
* The type to convert to
*
* @return The converter that should be used by this component
*/
@SuppressWarnings("unchecked")
@Override
public <C> IConverter<C> getConverter(Class<C> type) {
IConverter<?> converter = createConverter(type);
if (converter != null) {
return (IConverter<C>) converter;
}
return getApplication().getConverterLocator().getConverter(type);
}
/**
* Factory method for converters to be used by this component.
*
* parameter - returns {@code null} by default.
*
* @param type
* The type to convert to
*
* @return a converter to be used by this component
*/
protected IConverter<?> createConverter(Class<?> type) {
return null;
}
{code}
was (Author: svenmeier):
We could ease the pain with a new method on Component:
{code}
/**
* Gets the converter that should be used by this component.
*
* @param type
* The type to convert to
*
* @return The converter that should be used by this component
*
* @see #getRawConverter(Class)
*/
@SuppressWarnings("unchecked")
@Override
public <C> IConverter<C> getConverter(Class<C> type) {
IConverter<?> converter = getRawConverter(type);
if (converter == null) {
return (IConverter<C>) converter;
}
return getApplication().getConverterLocator().getConverter(type);
}
/**
* Convenience method to allow usage of converters without generic type
* parameter - returns {@code null} by default.
*
* @param type
* The type to convert to
*
* @return The converter that should be used by this component
*/
protected IConverter<?> getRawConverter(Class<?> type) {
return null;
}
{code}
> Reconsider generics of IConverterLocator#getConverter()
> -------------------------------------------------------
>
> Key: WICKET-5866
> URL: https://issues.apache.org/jira/browse/WICKET-5866
> Project: Wicket
> Issue Type: Improvement
> Components: wicket
> Affects Versions: 7.0.0
> Reporter: Sven Meier
> Assignee: Sven Meier
> Priority: Minor
> Fix For: 8.0.0-M2
>
>
> IConverterLocator#getConverter() has a generic parameter <C> currently.
> It seems to me that this is not very useful: almost all code calling #getConverter() does not care for the type parameter.
> From the user perspective it's very common to override Component#getConverter(). With the need for a cast and to suppress the generics warning, providing a custom converter is much too hard currently:
> {code}
> public <C> IConverter<C> getConverter(Class<C> clazz)
> {
> if (Date.class.isAssignableFrom(clazz))
> {
> @SuppressWarnings("unchecked")
> return (IConverter<C>)new DateConverter();
> }
> else
> {
> return super.getConverter(clazz);
> }
> }
> {code}
> I propose to remove the generics parameter from the method:
> {code}
> public IConverter<?> getConverter(Class<?> clazz)
> {
> if (Date.class.isAssignableFrom(clazz))
> {
> return new DateConverter();
> }
> else
> {
> return super.getConverter(clazz);
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)