我想要一个方法,它接受一个实现和返回的List<T>地方,或者取决于列表是否排序.TComparabletruefalse
在Java中实现它的最佳方法是什么?显而易见的是,泛型和通配符意味着能够轻松处理这些事情,但我总是纠缠不清.
有一个类似的方法来检查列表是否是相反的顺序也是很好的.
如果给定的集合包含给定顺序的给定项目,如何使用Hamcrest进行检查?我试过hasItems但它只是忽略了顺序.
List<String> list = Arrays.asList("foo", "bar", "boo");
assertThat(list, hasItems("foo", "boo"));
//I want this to fail, because the order is different than in "list"
assertThat(list, hasItems("boo", "foo"));
Run Code Online (Sandbox Code Playgroud)