如何处理重复的类型参数?
How are duplicate type parameters handled?
我有一个 class 看起来像这样。
// just followed the T, U, V...
public class Some<T...., U....> {
}
我需要添加一个像这样的实例方法。
// not a static method
// just followed from BiFunction<T, U, R>.class
protected <U, R> R apply(final BiFunction<T, U, R> function,
final U u) {
}
方法的T
与class的T
相同。
但是方法的U
不一定和class的U
一样。
我应该更改其中之一吗U
?
换句话说,
这两个U
一样吗?
不,根据范围规则,U
不相同。 apply
方法的 U
隐藏了 class Some
方法中的那个。为了避免混淆,我会重命名其中一个 U
s.
我有一个 class 看起来像这样。
// just followed the T, U, V...
public class Some<T...., U....> {
}
我需要添加一个像这样的实例方法。
// not a static method
// just followed from BiFunction<T, U, R>.class
protected <U, R> R apply(final BiFunction<T, U, R> function,
final U u) {
}
方法的T
与class的T
相同。
但是方法的U
不一定和class的U
一样。
我应该更改其中之一吗U
?
换句话说,
这两个U
一样吗?
不,根据范围规则,U
不相同。 apply
方法的 U
隐藏了 class Some
方法中的那个。为了避免混淆,我会重命名其中一个 U
s.