【问题标题】:How to use Function<? super String, ? extends String>如何使用函数<?超级字符串,?扩展字符串>
【发布时间】:2020-02-11 12:52:14
【问题描述】:

我正在尝试使用代理连接到服务器,但我正在创建的对象强制我创建Function &lt;? super string, ? extends String&gt;,但我不知道如何使用它。这个Function 是如何工作的?他问我密码

我的代码:

Function<? super String, ? extends String> pwd = username -> passProxy;
HttpClient httpClientAux = HttpClient.create().tcpConfiguration(tcpClient -> tcpClient.proxy(
                proxy -> proxy.type(ProxyProvider.Proxy.HTTP).address(new InetSocketAddress(urlProxy, 8080)).username(usuarioProxy).password(pwd)));
ReactorClientHttpConnector connector = new ReactorClientHttpConnector(httpClientAux);
this.myWebClient = webClientBuilder.clientConnector(connector).build();

【问题讨论】:

  • 你的代码有什么问题?

标签: spring spring-boot java-8 proxy spring-webflux


【解决方案1】:

Function 表示接受一个参数并产生结果的函数。

函数基本上有两个类型参数,第一个是INPUT参数类型,第二个是OUTPUT返回类型

Function<? super String, ? extends Integer> checkvalue = (str) -> str.length(); 
// takes String as parameter and produce length as Integer

在您的情况下Function &lt;? super string? extends String&gt; 将用户名字符串作为参数并生成密码字符串

来自文档https://projectreactor.io/docs/netty/release/api/reactor/netty/tcp/ProxyProvider.Builder.html#password-java.util.function.Function-

更多关于Functionhttps://www.baeldung.com/java-8-functional-interfaces

【讨论】:

    猜你喜欢
    • 2016-08-27
    • 2018-11-26
    • 1970-01-01
    • 1970-01-01
    • 2015-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多