Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 10th, 2012  |  syntax: None  |  size: 0.68 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Generic with Variable Type Arguments
  2. public interface Foo<R, P...> {
  3.     public R bar(P...) {/*misc*/}
  4. }
  5.        
  6. public class Foo<R, P> {
  7.   /*
  8.    * Not sure how you intend to provide any kind of implementation
  9.    * here since you don't know what R or P are.
  10.    */
  11.   public R bar(P parameters) { ... }
  12. }
  13.  
  14. public class SomeFoo extends Foo<SomeResult, Pair<Baz, Bar>> {
  15.   public SomeResult bar(Pair<Baz, Bar> parameters) { ... }
  16. }
  17.  
  18. SomeFoo foo = ...
  19. SomeResult result = foo.bar(Pair.of(baz, bar));
  20.        
  21. class TypedInstance<T>{
  22.    Class<T> type;
  23.    T instance;
  24. }
  25.        
  26. public whatever(TypedInstance<? extends Object>... whatever){
  27.   ...
  28.   doSomethingWith(whatever[0].type, whatever[0].instance);
  29.   ...
  30. }