title: Generic parameter type that accepts void
body: <p>I am trying to create an API for an open source project I am working on, and I have hit a speed bump in trying to extend the API while keeping the semantics consistent with the current API.  What I desire is to be able to define a method signature with a generic parameter that accepts the result of calling <em>any</em> method signature.  By "<em>any</em>", that is meant to include <code>void</code> methods.  I already know that you cannot directly define parameter types of <code>void</code> -- please do not repeat the obvious fact.  What is not obvious is whether there is any trick by which a <code>void</code> method call can be provided as an argument to a method (i.e., and ignored).</p>
  
  <p>Back story so this makes a little more sense why I would want to do such a thing, and what my design goal and constraints are, in case the above is impossible (as I fear it is):</p>
  
  <p>My current API defines a very repeatable pattern of methods like this:</p>
  
  <pre><code>public &lt;T,V&gt; Function&lt;T,V&gt; functionFor(V ignoredRetVal) {...}
  public &lt;T&gt;   Predicate&lt;T&gt;  predicateFor(V ignoredRetVal) {...}
  public &lt;T&gt;   Filter&lt;T&gt;     filterFor(V ignoredRetVal) {...}
  </code></pre>
  
  <p>As the names imply, the parameters are ignored and are not even used in the implementation.  In usage, <code>ignoredRetVal</code> is replaced with a method call to a dynamic proxy.  Since parameters are evaluated before the method is invoked, this dynamic proxy method is invoked before the outer function (<code>functionFor</code> or <code>predicateFor</code>, etc.).  The dynamic proxy invocation records the <code>Method</code> (or method chain) called, and converts this into a <code>Function</code> object (Guava) or other function-like object from multiple functional libraries.</p>
  
  <p>What I am trying to do now is create a similar semantic that captures method invocations that are used for side-effects only without any need for a return type (such as <a href="http://functionaljava.googlecode.com/" rel="nofollow">Functional Java's</a> <a href="http://functionaljava.googlecode.com/svn/artifacts/3.0/javadoc/fj/Effect.html" rel="nofollow"><code>Effect</code></a>.  If a non-void return type is provided, it is ignored.  If a void return type is provided, it too is ignored and accepted.  The key is that the semantics must somehow force the proxy method to be invoked before another method that extracts the intercepted proxied method calls.  And since we are only interested in side effects, candidate methods are likely to include <code>void</code> methods.  Ideally it would look something like:</p>
  
  <pre><code>public &lt;T, V&gt; Effect&lt;T&gt; effectFor(V ignoredRetVal) {...}
  </code></pre>
  
  <p>(which already works for non-void return types) and it could be used as follows:</p>
  
  <pre><code>Effect&lt;MyClass&gt; effect1 = effectFor (proxyOfMyClass.nonVoidMethod());// OK :-)
  Effect&lt;MyClass&gt; effect2 = effectFor (proxyOfMyClass.orVoidMethod()); // Problem!!
  </code></pre>
  
  <p>As I have said, I'm afraid the semantic I am looking for is not directly supportable.  If not, then any alternative should be close in spirit to the pattern I have established.  Also, the whole goal of my API was to reduce "vertical noise" of inner class implementations, and I am not a fan of Double Brace Initializers. Whatever suggestions are offered, I am looking for a semantic that supports brevity, especially a single-statement semantic.</p>