Uploaded image for project: 'Click'
  1. Click
  2. CLK-609

Use generics where appropriable

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.2.0
    • Component/s: core, extras
    • Labels:
      None

      Description

      Because Click requires Java 1.5, Click can use its generics support.
      For example:

      Context:
      public <T extends Page> T createPage (Class<T> pageClass)

      { return clickServlet.createPage(pageClass, request); }

      @SuppressWarnings("unchecked")
      public <T extends Page> T createPage (String path)

      { return (T) clickServlet.createPage(path, request); }

      ClickServlet:
      @SuppressWarnings("unchecked")
      protected <T extends Page> T createPage (Class<T> pageClass, HttpServletRequest request) {
      String path = getConfigService().getPagePath(pageClass);

      if (path == null)

      { throw new IllegalArgumentException("No path configured for Page class: " + pageClass.getName()); }

      return (T) initPage(path, pageClass, request);
      }

      then you can do:

      MyPage1 x = getContext() .createPage(MyPage1.class);//no explicit cast

      getContext() .createPage(String.class);//compilation error, red code in IDE

      AdminPage p = getContext() .createPage("/admin/edit.htm");// implicitly cast - Runtime check, but looks nice

        Attachments

          Activity

            People

            • Assignee:
              sabob Bob Schellink
              Reporter:
              andreyrybin Andrew Fink
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: