1. First deal with the two options for conversion of explicit generics
Registry<ConnectionSocketFactory> socketFactoryRegistry = null; Registry cast = socketFactoryRegistry.getClass().cast(RegistryBuilder.create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", new SSLConnectionSocketFactory(sslcontext, hostnameVerifier)).build()); final Registry<Object> build = RegistryBuilder.create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", new SSLConnectionSocketFactory(sslcontext, hostnameVerifier)).build(); Object temp = build; Registry<ConnectionSocketFactory> socketFactoryRegistry1 = (Registry<ConnectionSocketFactory>) temp;
2. References
Mutual conversion between generics and entity classes - Diandian_Didi- Blog Park (cnblogs.com)
(542 messages) Generic cast error Unchecked cast: 'java.lang.XXX' to 'T'-CSDN Blog