Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: BSD License 

import java.util.*;
import java.lang.reflect.*;

public class Main {
    private static <T> Collection<T> newCollection(Collection<T> coll) {
        try {
            Class cl = coll.getClass();
            Constructor con = cl.getConstructor(new Class[0]);
            return (Collection<T>) con.newInstance(new Object[0]);
        } catch (Exception e) {
            if (coll instanceof List)
                return new LinkedList<T>();
            if (coll instanceof Set)
                return new HashSet<T>();
            throw new RuntimeException("Cannot handle this collection");
        }
    }
}