Keep bounded wildcards out of return values.
不要对返回值使用通配符。
Bounded wildcards work best when they are used in APIs, not in client code.
有界通配符最适合用于API,而不是客户机代码。
Bounded wildcards are extremely useful in making generic APIs more flexible.
有界通配符对于提高泛型api的灵活性极其有用。
The biggest impediment to using bounded wildcards correctly is the perception that we don't need to use them!
正确使用有界通配符的最大绊脚石是认为没有必要使用它们。
Lower-bounded wildcards show up when you want to specify a callback object, such as a comparator, or a data structure into which you are going to place a value.
当您希望指定一个回调对象(例如一个比较器)或存放某个值的数据结构,可以使用下限通配符。
Some situations will call for lower-bounded wildcards, and some for upper-bounded ones, and the get-put principle can be used to determine which should be used.
有些情况适合使用下限通配符,而另一些情况则适合使用上限通配符,通过get - put原则可以判断应该使用哪种通配符。
As a final example of using lower bounded wildcards, lets look at the method Collections. Max , which returns the maximal element in a collection passed to it as an argument.
作为使用下界通配符的最后一个例子,让我看看方法Collections.max,返回传递给它作为参数的集合的最大元素。
The most common mistake with bounded wildcards is forgetting to use them at all, restricting the utility of a class or forcing users to jump through hoops to reuse an existing class.
最常见的有界通配符错误就是忘记使用它们,这就限制了类的使用,或是强制用户不得不重用现有的类。
The most common mistake with bounded wildcards is forgetting to use them at all, restricting the utility of a class or forcing users to jump through hoops to reuse an existing class.
最常见的有界通配符错误就是忘记使用它们,这就限制了类的使用,或是强制用户不得不重用现有的类。
应用推荐