1、package com.zhang.thread.threadlocal01;public class Run { public static ThreadLocal<String> t1 = new ThreadLocal<>(); public static void main(String[] args) { if(t1.get() == null){ System.out.println("t1从来没有放过值"); t1.set("hello"); } System.out.println(t1.get()); System.out.println(t1.get()); }}

2、get()为空时,说明ThreadLocal中从来没有放过值;当ThreadLocal中存在值时,可以使用get()从中取值,值依然保留