How to pass a member function as a parameter in java?
<p>My <code>collect()</code> function calls <code>Foo.f()</code>. I would like to make <code>Foo.f()</code> itself a parameter of my function. Is this possible in Java? </p>

<ul>
<li>How can I pass either <code>Foo.f()</code> or <code>Foo.g()</code> (or any other function of <code>Foo</code> that returns a <code>String</code>) to my function?</li>
<li>Is there an already existing function which walks a collection and collects the result of calling a method of every collection item?</li>
</ul>

<p>.</p>

<pre><code>class Foo {
    public String f() { return "f"; }
    public String g() { return "g"; }
    // ...
}

public List&lt;String&gt; collect(List&lt;Foo&gt; foos)
{
    List&lt;String&gt; result = new ArrayList&lt;String&gt;();

    for (final Foo foo: foos) {
        result.add(foo.f());  // I want Foo.f to be a parameter
    }

    return result;
}
</code></pre>

<p><strong>Update</strong></p>

<p>I would like to point out the fact that I am not merely calling the same function but rather the member function <code>f</code> for all items of the <code>List&lt;Foo&gt;</code> collection.</p>
