@Test public void canCastAAsyncClient() { HttpAsyncClient build = HttpAsyncClientBuilder.create().build(); assertEquals(true, Util.tryCast(build, CloseableHttpAsyncClient.class).isPresent()); }
static <T, M extends T> Optional<M> tryCast(T original, Class<M> too) { if (original != null && too.isAssignableFrom(original.getClass())) { return Optional.of((M) original); } return Optional.empty(); }
Util { static <T, M extends T> Optional<M> tryCast(T original, Class<M> too) { if (original != null && too.isAssignableFrom(original.getClass())) { return Optional.of((M) original); } return Optional.empty(); } }
Util { static <T, M extends T> Optional<M> tryCast(T original, Class<M> too) { if (original != null && too.isAssignableFrom(original.getClass())) { return Optional.of((M) original); } return Optional.empty(); }  }
Util { static <T, M extends T> Optional<M> tryCast(T original, Class<M> too) { if (original != null && too.isAssignableFrom(original.getClass())) { return Optional.of((M) original); } return Optional.empty(); }   }
Util { static <T, M extends T> Optional<M> tryCast(T original, Class<M> too) { if (original != null && too.isAssignableFrom(original.getClass())) { return Optional.of((M) original); } return Optional.empty(); }    }