Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Kudos to you for the sheer awesomeness of this question. You're pretty much up against the limits of what Java can do. (Though, of course, delegating like you describe would be a breeze in any functional language.)</p> <p>First of all, limitation #2 should not be an issue. As of 1.5, Java no longer restricts you to fixed declarations in methods. You can use an ellipsis to indicate a variable number of arguments, like <a href="http://www.deitel.com/articles/java_tutorials/20060106/VariableLengthArgumentLists.html" rel="nofollow noreferrer">so</a></p> <pre><code>public static double average( double... numbers ) { double total = 0.0; for (double d : numbers) { total += d; } return total / numbers.length; } </code></pre> <p>I'm not entirely sure how to get around limitation #1, but I'm thinking about something with <a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html" rel="nofollow noreferrer">generics</a> and/or <a href="http://www.javaworld.com/javaworld/javaqa/2000-03/02-qa-innerclass.html" rel="nofollow noreferrer">anonymous inner classes</a>. I'm guessing here -- I haven't tried doing this myself -- but you could create a map of function names and delegate classes like so:</p> <pre><code>public interface Callback {...} public interface AddUserCallBack extends Callback {...} public class UserImpl&lt;T extends Callback&gt; { public T getDelegateRoutine(); ... } </code></pre> <p>Generics in Java have some hair-pulling frustrations associated with them, primarily due to type erasure. You may need to juggle both interfaces and abstract base classes before you get it to do what you want. But something like this should work for you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload