问题描述
如何创建 Apache Commons Lang 3.1 Range
对象?
JavaDocs 说:
从最小到最大点的不可变对象范围."
"对象要么是 Comparable 的实现,要么您需要提供一个 Comparator."
但是当我尝试时:
范围range = new Range(100, 200);
我的 IDE 中出现错误,提示所需参数为整数、整数、比较器.
即使 Integer
实现了 Comparable
接口,因此我不需要额外的比较器.
谁能举一个例子来说明如何构造上述Range
对象?
Range 的构造函数似乎是私有的,因此静态方法可能是构造对象的首选方式.
例如,您似乎可以使用静态方法 between
来构造范围:
Range.between(100, 200);
但是还有其他静态方法,这取决于您的需要.
How can I create a Apache Commons Lang 3.1 Range<Inreger>
object?
The JavaDocs say:
But when I try:
Range<Integer> range = new Range<Integer>(100, 200);
I get an error in my IDE that says required arguments are Integer, Integer, comparator.
Even though Integer
implements the Comparable
interface and thus I shouldn't need a extra comparator.
Can someone give me an example of how to construct the above described Range<Integer>
object?
The constructor of Range appears to be private so a static method may be the preferred way of constructing the object.
For example, it looks like you could use the static method between
to construct a Range:
Range.between(100, 200);
However there are other static methods, it just depends what you need.
这篇关于如何构建 Apache Commons Lang Range<Integer>目的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!