我有下面的代码,可以在JDK5上运行
private static ThreadLocal<String> messages = new ThreadLocal<String>();
private static ThreadLocal<Boolean> dontIntercept = new ThreadLocal<Boolean>() {
@Override
protected Boolean initialValue() {
return Boolean.FALSE;
}
};我希望在JDK1.4上运行它。请告诉我需要做哪些改动
发布于 2010-02-05 19:49:22
@Override批注。所以
private static final ThreadLocal messages = new ThreadLocal();
private static final ThreadLocal dontIntercept = new ThreadLocal() {
protected Object initialValue() {
return Boolean.FALSE;
}
};在使用时
使用带Boolean.valueOf.的.booleanValue().
Boolean.valueOf.发布于 2010-02-05 18:51:44
在使用get和put方法时,必须去掉泛型,然后对值进行适当的转换。您还需要确保布尔ThreadLocal在代码中使用的位置被正确初始化。
发布于 2010-02-05 21:45:22
如果程序被正确地写成Java1.4行为,但使用表示法,我们已经使用过多次的方法是使用1.5+将编译的Java1.5字节码转换成Java1.4字节码。
http://retroweaver.sourceforge.net/
其他的是存在的,但这是我们发现的最好的。
https://stackoverflow.com/questions/2206534
复制相似问题