hk2
  1. hk2
  2. HK2-92

Generic signature for ServiceLocator methods allows any return type

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1.*
    • Fix Version/s: 2.1.*
    • Component/s: None
    • Labels:
      None

      Description

      Due to the fact that Type has no generic component, this is possible:

      Integer i = testLocator.getService(Double.class);

      The signature for getService currently is:

      public <T> T getService(Type contractOrImpl, Annotation... qualifiers)

      Since there is no generic type in the paramter list the return type can be anything at all. The question is should we add methods to ServiceLocator like:

      public <T> T getService(Class<?> contractOrImpl, Annotation... qualifiers)

      where appropriate in order to have more type checking? This would add around six API but would perhaps make the use of the API somewhat easier.

        Activity

        Hide
        jwells added a comment -

        Sorry, that should read:

        public <T> T getService(Class<T> contractOrImpl, Annotation... qualifiers)

        Note the "T" in the Class signature.

        Show
        jwells added a comment - Sorry, that should read: public <T> T getService(Class<T> contractOrImpl, Annotation... qualifiers) Note the "T" in the Class signature.
        Hide
        jwells added a comment -

        Added a cooresponding Class<T> for every API that took a Type.

        Show
        jwells added a comment - Added a cooresponding Class<T> for every API that took a Type.

          People

          • Assignee:
            jwells
            Reporter:
            jwells
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: