How to use multiple upper bounds in generics

I have a Foo interface that has a generic type -

 public interface Foo<T> {  
     boolean apply(T t);  
 }

Having another Bar class that implements this interface, but what I want is a generic Bar type, which should be an assembly of type Interface A and B, with the definition below giving a compiler error -

public class Bar implements Foo<Collection<? extends A & B>>{
  @Override
  public boolean apply(Collection<? extends A & B> collect){
   ...
  }  
}

Can you suggest the right way to achieve this?

Can I use only a few borders only at the method level?

+5
source share
1 answer

Does this work?

public class Bar<T extends A & B> implements Foo<Collection<T>>{
  @Override
  public boolean apply(Collection<T> collect){
   ...
  }  
}
+10
source