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