错误写法:
public static T get(Supplier<T> sup) {
return sup.get();
}
正确写法:
public static<T> T get(Supplier<T> sup) {
return sup.get();
}
本文介绍了在Java中使用泛型与静态方法时遇到的错误情况,通过展示错误的代码片段,并详细解释了如何修正这些错误,确保静态方法能正确处理泛型类型。
错误写法:
public static T get(Supplier<T> sup) {
return sup.get();
}
正确写法:
public static<T> T get(Supplier<T> sup) {
return sup.get();
}
2712
188
2929

被折叠的 条评论
为什么被折叠?