HaniiPuppy

Untitled

Apr 10th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. class Foo<T extends Qux>
  2. {
  3.     Collection<Bar<T>> bars;
  4.     T qux;
  5.  
  6.     public Collection<Bar<T>> getBars()
  7.     { return bars; }
  8.  
  9.     public qux getQux()
  10.     { return qux; }
  11. }
  12.  
  13. class Bar<T extends Qux>
  14. {
  15.     public void barMethod(T quxarg)
  16.     { // stuff }
  17. }
  18.  
  19. class SomeClass
  20. {
  21.     public static someMethod(Foo<? extends Qux>... foos)
  22.     {
  23.         for(Foo<? extends Qux> i : foos)
  24.         {
  25.             for(Bar<? extends Qux> j : i.getBars())
  26.             {
  27.                 j.barMethod(i.getQux);
  28.                 // Error: Cannot convert Qux to capture#1 of ? extends Qux
  29.  
  30.                 // Is there a better way to do this?
  31.                 // The type parameter of j is guaranteed to be  the same type parameter as i's
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment