小编Sha*_*ika的帖子

Java 8流max()函数参数类型Comparator与Comparable

我写了一些简单的代码,如下所示。此类正常运行,没有任何错误。

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参数一起使用。

我知道我误会了一些东西,但是现在我知道了。有人可以解释一下吗?

java java-8 java-stream

17
推荐指数
3
解决办法
1320
查看次数

Spring 5 WebFlux Mono和Flux

在Spring 5中,我只知道Spring WebFlux Handler方法处理请求并返回MonoFlux作为响应.

@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)

但我不知道MonoFlux是什么意思,以及它如何与WebFlux Handler协同工作.

可以任何人简单解释一下

1.什么意思是MonoFlux.

2.它如何与WebFlux处理程序一起使用.

提前致谢.

spring java-8 spring-boot spring-webflux

5
推荐指数
1
解决办法
5224
查看次数

此计算机未在 minikube 上启用 VT-X/AMD-v - Windows 10

!StartHost 失败,但将重试:正在创建主机:创建:预创建:此计算机未启用 VT-X/AMD-v。必须在 BIOS 中启用它

当我在 Windows 计算机中执行 [minikube start --driver=virtualbox] 命令时,我遇到了这个问题。我已经在我的机器中启用了 VT-X/AMD-v。

virtualbox kubernetes windows-10 minikube

3
推荐指数
1
解决办法
3413
查看次数

在jsp/servlet中弹出一个消息框

我正在研究JSP/servlet应用程序.
我想在将用户数据插入数据库表后在JSP/servlet中弹出一个消息警告框.

jsp

2
推荐指数
1
解决办法
3万
查看次数