title: Java Interface method supporting variable number of arguments with different types
body: <p>I would like to build an interface containing a method that can take a variable number of arguments of various types, something like as follows:</p>
  <pre><code>interface MyInterface {
  
     boolean myMethod(Object ...args); &lt;--HERE I WOULD LIKE TO PASS ANY NUMBER OF PARMS OF ANY TYPE
  
  }
  </code></pre>
  <p>In the concrete implementations of the interface, I would like to pass any number of params of any type as follows:</p>
  <pre><code>class MyImpl1 implements MyInterface {
  
     boolean myMethod(Student s, Course d) {
        ...
     }
  }
  </code></pre>
  <p>Another implementation could be as follows:</p>
  <pre><code> class MyImpl2 implements MyInterface {
  
     boolean myMethod(Department d) {
        ...
     }
  }
  </code></pre>
  <p>In this regard, I have gone through a few posts here, but not getting any idea regarding how to do this. Could anyone please help here? Thanks.</p>
  <p><strong>EDIT:</strong></p>
  <p>I have thought of the exact interface structure to be like below:</p>
  <pre><code>interface ConditionEvaluator {
       
       boolean evaluate(Object ...args);
       CondtionName getConditionName();
     }
  </code></pre>
  <p>One concrete implementation will look something like this:</p>
  <pre><code>class StudentEvaluator implements MyInterface {
    
      boolean evaluate(Student s, List&lt;Course&gt; courses) {
        ...
      }
    
      ConditionType getConditionType() {
         return ConditionType.STUDENT_PASSED;
      }
   }
  </code></pre>
  <p>To use this, I have thought that, I will create an enum map, containing ConditionType as key and concrete implementations as values as follows:</p>
  <pre><code>Map&lt;ConditionType, MyInterface&gt; conditionTypeMap;
  </code></pre>
  <p>Then from the caller method, was thinking of deriving appropriate implementation based on appropriate <code>ConditionType</code>.</p>
  <p>Usage is somewhat like below,</p>
  <p>I will have a factory class as follows:</p>
  <pre><code>@Component
  public class ConditionEvaluatorFactory {
  
    private final Map&lt;ConditionType, ConditionEvaluator&gt; conditionEvaluatorMap;
  
    public ConditionEvaluatorFactory(List&lt;ConditionEvaluator&gt;
                                            conditionEvaluatorList) {
      Map&lt;ConditionTyope, ConditionEvaluator&gt; evaluatorMap =
          new EnumMap&lt;&gt;(ConditionEvaluator.class);
      for (ConditionEvaluator evaluator :
          conditionEvaluatorList) {
        evaluatorMap.put(evaluator.getConditionType(),
            evaluator);
      }
      this.conditionEvaluatorMap = evaluatorMap;
    }
  
    public ConditionEvaluator getEvaluator(ConditionType conditionType) {
      ConditionEvaluator evaluator = conditionEvaluatorMap
          .get(conditionType);
      if (evaluator == null) {
        throw new Exception(&quot;error message&quot;);
      }
      return evaluator;
    }
  }
  </code></pre>
  <p>Caller class is as follows:</p>
  <pre><code>@component
  class StudentUtil {
  
   @Autowired
   private ConditionEvaluatorFactory evaluatorFactory;
  
   public void callerFunc(Student s, List&lt;Course&gt; courseList) {
      boolean flag = evaluatorFactory.getEvaluator(ConditionType.STUDENT_PASSED).evaluate(s, courseList);
   ...
      
   }
  </code></pre>