Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    private static ThreadLocal<Object> threadLocal = new ThreadLocal<Object>();

    public static <T> T get(Class<T> cls) {
        try {
            T t = cls.cast(threadLocal.get());
            return t;
        } catch (Exception ex) {
            return null;
        } finally {
            remove();
        }
    }

    public static void remove() {
        threadLocal.remove();
    }
}