泛型相关知识的总结

1、先处理已明确泛型的转换的两种方案

 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、参考文献

泛型 与 实体类的相互转换 - 点点_滴滴 - 博客园 (cnblogs.com)

 

(542条消息) 泛型强制转换报错 Unchecked cast: ‘java.lang.XXX‘ to ‘T‘-CSDN博客

(542条消息) 在 Java 中,类、类对象、泛型之间的转换_泛型t转化为具体class_暗诺星刻的博客-CSDN博客

猜你喜欢

转载自blog.csdn.net/yz18931904/article/details/130912796
今日推荐