如何减少 java 线程本地的冗长冗余

How to reduce the verbose redundancy of java thread local

我有一个 class,我想声明一个私有成员,它是一个线程本地字典。这就是它的样子...

private static ThreadLocal<HashMap<Integer, Measurement>> measurements = 
        new ThreadLocal<HashMap<Integer, Measurement>>() 
{
    @Override protected HashMap<Integer, Measurement> initialValue()
    {
        return new HashMap<Integer, Measurement>();
    }

};

如您所见,我必须键入 HashMap<Integer, Measurement> 多得离谱的次数。有没有办法让这个更简洁?

这个怎么样?

private static ThreadLocal<HashMap<Integer, Measurement>> measurements = ThreadLocal.withInitial(HashMap::new);