获取泛型参数的泛型类型
[Java]代码
01 | GenericKeyedObjectPool objectPool = new GenericKeyedObjectPool( new KeyedPoolableObjectFactory() { |
04 | public boolean validateObject(Object key, Object obj) { |
05 | return obj != null && (key.equals(JSONParser. class ) || key.equals(XmlRpcClient. class )); |
09 | public void passivateObject(Object key, Object obj) throws Exception { |
10 | if (key.equals(JSONParser. class )) { |
11 | ((JSONParser) obj).reset(); |
16 | public Object makeObject(Object key) throws Exception { |
17 | if (key.equals(JSONParser. class )) |
18 | return new JSONParser(); |
19 | if (key.equals(XmlRpcClient. class )) { |
20 | XmlRpcClient client = new XmlRpcClient(); |
23 | throw new IllegalArgumentException( "unknown key type for KeyObjectPool!" ); |
27 | public void destroyObject(Object key, Object obj) throws Exception { |
31 | public void activateObject(Object key, Object obj) throws Exception { |
33 | }, poolSize, GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, - 1 ); |
原文地址:https://www.cnblogs.com/shihao/p/2693100.html