title: Is it possible to cycle through function arguments in Java?
body: <p>I am using Dagger dependency injection to initiate a list of <code>Foo</code> elements that will get passed to another object. Here is essentially the code:</p>
  
  <pre><code>@Provides
  @Singleton
  public List&lt;Foo&gt; provideList(@Named("foo1") Foo foo1, @Named("foo2") Foo foo2) {
      List&lt;Foo&gt; list = new ArrayList&lt;&gt;();
      list.add(foo1);
      list.add(foo2);
      return list;
  }
  </code></pre>
  
  <p>As time progresses, we expect to add more and more <code>Foo</code> arguments to this method. To make the code more durable, I'd like to do something like the following:</p>
  
  <pre><code>@Provides
  @Singleton
  public List&lt;Foo&gt; provideList(@Named("foo1") Foo foo1, @Named("foo2") Foo foo2) {
      List&lt;Foo&gt; list = new ArrayList&lt;&gt;();
  
      args.forEach(arg -&gt; {
          if (arg instanceof Foo) list.add((Foo) arg);
      });
  
      return list;
  }
  </code></pre>
  
  <p>Is anything like this possible in Java?</p>