Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Collections;
import java.util.List;

public class Main {
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static <T> void checkedAtRuntime(List<T> list, Class<T> clazz, Object data) {
        List tryToAddNotTStuff = Collections.checkedList(list, clazz);
        try {
            tryToAddNotTStuff.add(data);
        } catch (ClassCastException e) {
            System.out.println("can't add data different that expected");
        }
        System.out.println(tryToAddNotTStuff);
    }
}