Uploaded image for project: 'Service Design and Creation'
  1. Service Design and Creation
  2. SDC-2812 Refactor all usage of Eithers
  3. SDC-3040

Remove wildcard pattern when retrieving components

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Done
    • Icon: Medium Medium
    • None
    • None
    • None
    • None

      Some eithers use generics in a not optimal way in:

      • CertificationChangeTransition
      • LifeCycleTransition
      • LifecycleBusinessLogic
      Bar.java
      private Either<? extends Component, SomeType> methodName(/*...*/)
      // should be replaced by
      private <T extends Component> Either<T, SomeType> methodName(/*...*/)
      

      As explained in Effective Java, the wildcard pattern should only be used following the PECS pattern:

      • Use the <? extends T> wildcard if you need to retrieve object of type T from a collection.
      • Use the <? super T> wildcard if you need to put objects of type T in a collection
      • If you need to satisfy both things, well, don’t use any wildcard.

      In this case, fixing the type is enough as we don't know if the result will be stored or consumed. Secondly this prevents extra unsafe casting when retrieving components.

            francistoth francistoth
            francistoth francistoth
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: