Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Main {
    @SuppressWarnings("unchecked")
    public static <X, Y extends X> List<Y> getObjectsOfType(Collection<X> objs, Class<Y> cls) {
        List<Y> ret = new ArrayList<Y>();
        if (objs != null) {
            for (X obj : objs) {
                if (cls.isInstance(obj)) {
                    ret.add((Y) obj);
                }
            }
        }
        return ret;
    }
}