Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-1991

Wrong overloaded method invoked on decorator

    XMLWordPrintable

Details

    Description

      The following interface defines two overloaded methods. Both take one parameter where one is of type "java.util.Collection", the other one of "java.util.Set":

      public interface MyService {
      
        void run(Collection<String> values);
      
        void run(Set<Integer> values);
      
      }
      

      Furthermore a decorator is defined:

      @Decorator
      public interface MyServiceDecorator {
      
        @Inject @Delegate
        private MyService delegate;
      
        void run(Collection<String> values) {
          delegate.run(values);
        }
      
        void run(Set<Integer> values) {
          delegate.run(values);
        }
      
      }
      

      A client injects an instance of MyService and invokes "run" using a Set of integer values:

        @Inject
        private MyService myService;
      
        ...
          Set<Integer> values = new HashSet<>();
          myService.run(values);
        ...
      

      It can be observed that the method " void run(Collection<String> values)" is invoked on the decorator - which is wrong. Changing the order of the method declarations in the interface MyService "solves" the problem.

      Attachments

        Activity

          People

            mkouba@redhat.com Martin Kouba
            dirk-mahler Dirk Mahler (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: