how to construct a apache commons 3.1 Range<Integer> object

泪湿孤枕 提交于 2019-12-04 03:28:13

问题


How can I create a apache commons 3.1 Range object?

The java docs say:

"An immutable range of objects from a minimum to maximum point inclusive."

"The objects need to either be implementations of Comparable or you need to supply a Comparator."

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 a apache commons 3.1 Range object?


回答1:


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.




回答2:


Range is an abstract class. Use IntRange range = new IntRange(100, 200) instead.



来源:https://stackoverflow.com/questions/13626491/how-to-construct-a-apache-commons-3-1-rangeinteger-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!