Java tutorial
//package com.java2s; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Collection; public class Main { /** * Creates a new empty instance of the provided collection * * @param <T> * @param in * @return */ public static <T> Collection<T> createEmpty(Collection<?> in) { Class<?> originalClass = in.getClass(); try { Constructor<?> originalConstructor = originalClass.getConstructor(new Class[0]); return (Collection<T>) originalConstructor.newInstance(new Object[0]); } catch (IllegalArgumentException e) { } catch (InstantiationException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } catch (SecurityException e) { } catch (NoSuchMethodException e) { } finally { return null; } } }