我写了一些简单的代码,如下所示。此类正常运行,没有任何错误。
public class Test {
public static void main(String[] args) {
List<Integer> intList = IntStream.of(1,2,3,4,5,6,7,8,9,10).boxed().collect(Collectors.toList());
int value = intList.stream().max(Integer::compareTo).get();
//int value = intList.stream().max(<Comparator<? super T> comparator type should pass here>).get();
System.out.println("value :"+value);
}
}
Run Code Online (Sandbox Code Playgroud)
如代码注释所示,该max()方法应传递type参数Comparator<? super Integer>。
但是Integer::compareTo实现Comparable接口- 不是 Comparator。
public final class Integer extends Number implements Comparable<Integer> {
public int compareTo(Integer anotherInteger) {
return compare(this.value, anotherInteger.value);
}
}
Run Code Online (Sandbox Code Playgroud)
这怎么工作?该max()方法说它需要一个Comparator参数,但是可以与Comparable参数一起使用。
我知道我误会了一些东西,但是现在我知道了。有人可以解释一下吗?
在Spring 5中,我只知道Spring WebFlux Handler方法处理请求并返回Mono或Flux作为响应.
@Component
public class HelloWorldHandler {
public Mono<ServerResponse> helloWorld(ServerRequest request) {
return ServerResponse.ok().contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromObject("Hello World"));
}
}
Run Code Online (Sandbox Code Playgroud)
但我不知道Mono和Flux是什么意思,以及它如何与WebFlux Handler协同工作.
可以任何人简单解释一下
1.什么意思是Mono和Flux.
2.它如何与WebFlux处理程序一起使用.
提前致谢.
!StartHost 失败,但将重试:正在创建主机:创建:预创建:此计算机未启用 VT-X/AMD-v。必须在 BIOS 中启用它
当我在 Windows 计算机中执行 [minikube start --driver=virtualbox] 命令时,我遇到了这个问题。我已经在我的机器中启用了 VT-X/AMD-v。
我正在研究JSP/servlet应用程序.
我想在将用户数据插入数据库表后在JSP/servlet中弹出一个消息警告框.
java-8 ×2
java ×1
java-stream ×1
jsp ×1
kubernetes ×1
minikube ×1
spring ×1
spring-boot ×1
virtualbox ×1
windows-10 ×1