Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-231

Not return the base interface on decorate

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.2
    • 4.0-alpha1, 4.0
    • Map
    • None

    Description

      At the moment I don't see a reason why the static "decorate" method does not return ListOrderedMap but just the base interface OrderedMap.

      I want to decorate a Map to be a ListOrderedMap but due to the fact that the constructor is not visible and decorate only returns the base interface OrderedMap an unnecessary cast is required.

      ListOrderedMap map = (ListOrderedMap)ListOrderedMap.decorate(new MyMap());

      As the decorate method is static and not part of any interface it should be fine to return the real type instead of the base. Otherwise I'd suggest to make the constructor visible. From the API POV It is not really understandable why this

      ListOrderedMap map = new ListOrderedMap();

      is fine and creates a HashMap under the hood while this

      ListOrderedMap map = new ListOrderedMap(new MyMap()));

      is not ok.

      Attachments

        Activity

          People

            Unassigned Unassigned
            tcurdt Torsten Curdt
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: