Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-5866

Reconsider generics of IConverterLocator#getConverter()

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 7.0.0
    • 8.0.0-M2, 7.5.0
    • wicket
    • None

    Description

      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:

          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);
               }
           }
      

      I propose to remove the generics parameter from the method:

          public IConverter<?> getConverter(Class<?> clazz)
           {
               if (Date.class.isAssignableFrom(clazz))
               {
                   return new DateConverter();
               }
               else
               {
                   return super.getConverter(clazz);
               }
           }
      

      Attachments

        Activity

          People

            svenmeier Sven Meier
            svenmeier Sven Meier
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: