public static void main(String[] args) { String[] arr = new String[3]; List<String> list = new ArrayList<String>(); if (list instanceof Collection) System.out.println("" + "true"); else System.out.println("" + "false"); System.out.println(arr.getClass()); System.out.println(list.getClass()); }
public static void main(String[] args) { List<Frob> list = new ArrayList<Frob>(); Map<Frob, Fnorkle> map = new HashMap<Frob, Fnorkle>(); Quark<Fnorkle> quark = new Quark<Fnorkle>(); Particle<Long, Double> p = new Particle<Long, Double>(); System.out.println(Arrays.toString(list.getClass().getTypeParameters())); System.out.println(Arrays.toString(map.getClass().getTypeParameters())); System.out.println(Arrays.toString(quark.getClass().getTypeParameters())); System.out.println(Arrays.toString(p.getClass().getTypeParameters())); }
public void show() { System.out.println(cid); System.out.println(cname); System.out.println(email); System.out.println(phone); System.out.println(emails); System.out.println(phones); System.out.println(refs); System.out.println(myprops); System.out.println(address); for (Account acc : accounts) { System.out.println(acc); } System.out.println(emails.getClass().getName()); System.out.println(phones.getClass().getName()); System.out.println(myprops.getClass().getName()); }
private <E> Object executeForMany(SqlSession sqlSession, Object[] args) { List<E> result; Object param = method.convertArgsToSqlCommandParam(args); if (method.hasRowBounds()) { RowBounds rowBounds = method.extractRowBounds(args); result = sqlSession.<E>selectList(command.getName(), param, rowBounds); } else { result = sqlSession.<E>selectList(command.getName(), param); } // issue #510 Collections & arrays support if (!method.getReturnType().isAssignableFrom(result.getClass())) { if (method.getReturnType().isArray()) { return convertToArray(result); } else { return convertToDeclaredCollection(sqlSession.getConfiguration(), result); } } return result; }
/** * ArrayList<String>和ArrayList<Integer>很容易认为是不同的类型, 不同的类型在行为方面肯定不同 但输出发现c1==c2为true * * @param args */ public static void main(String[] args) { Class c1 = new ArrayList<String>().getClass(); Class c2 = new ArrayList<Integer>().getClass(); System.out.println(c1 == c2); // 输出为true List<Frob> list = new ArrayList<Frob>(); Map<Frob, Fnorkle> map = new HashMap<Frob, Fnorkle>(); Quark<Fnorkle> quark = new Quark<Fnorkle>(); Particle<Long, Double> part = new Particle<Long, Double>(); // Class.getTypeParameters()将返回一个Typeariable对象数组,表示有泛型声明 // 的类型参数... System.out.println(Arrays.toString(list.getClass().getTypeParameters())); System.out.println(Arrays.toString(map.getClass().getTypeParameters())); System.out.println(Arrays.toString(quark.getClass().getTypeParameters())); System.out.println(Arrays.toString(part.getClass().getTypeParameters())); /** 输出结果: [E] [K, V] [Q] [POSITION, MOMENTUM] */ /** * 输出结果是一些占位符 说明:在泛型代码内部,无法获得任何有关泛型参数类型的信息。 当你在使用泛型时,任何具体的类型信息都被擦除了,你唯一知道的就是你在使用一个对象。 * 因此,List<String>和List<Integer>在运行时事实上是相同的类型。这两种形式都被 擦除成它们的原生类型,即List */ }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("[Bean, list "); if (_beans == null) { sb.append("NULL"); } else { sb.append('(').append(_beans.size()).append('/'); sb.append(_beans.getClass().getName()).append(") "); boolean type = false; for (CtorValueBean bean : _beans) { if (!type) { sb.append("(").append(bean.getClass().getSimpleName()).append(")"); type = true; } sb.append(bean); sb.append(' '); } } sb.append(']'); return sb.toString(); }