fork(1) download
  1. class SO52915280 {
  2. public static void main(String[] args) throws Exception {
  3. StringCommandBusRequest request = new StringCommandBusRequest();
  4. Bus<CommandBus> bus = new CommandBus();
  5. String result = bus.execute(request);
  6. }
  7.  
  8. public interface Bus<B extends Bus<B>> {
  9. <R, Q extends BusRequest<R, B>> R execute(Q request);
  10. }
  11.  
  12. public interface BusRequest<R, B extends Bus<B>> {}
  13.  
  14.  
  15. public static class CommandBus implements Bus<CommandBus> {
  16. @Override
  17. public <R, Q extends BusRequest<R, CommandBus>> R execute(Q request) {
  18. System.out.println("Got request of type: " + request.getClass());
  19. return null;
  20. }
  21. }
  22.  
  23. public interface CommandBusRequest<T> extends BusRequest<T, CommandBus> {}
  24.  
  25. public static class StringCommandBusRequest implements CommandBusRequest<String> {}
  26. }
Success #stdin #stdout 0.05s 2184192KB
stdin
Standard input is empty
stdout
Got request of type: class SO52915280$StringCommandBusRequest