我正在尝试使用Java中的Lambda表达式来理解以下方法参考代码:
interface MyFunc<T> {
boolean func(T v1, T v2);
}
class HighTemp {
private int hTemp;
HighTemp(int ht) {
hTemp = ht;
}
boolean sameTemp(HighTemp ht2) {
return hTemp == ht2.hTemp;
}
boolean lessThanTemp(HighTemp ht2) {
return hTemp < ht2.hTemp;
}
}
class InstanceMethWithObjectRefDemo {
static <T> int counter(T[] vals, MyFunc<T> f, T v) {
int count = 0;
for (int i = 0; i < vals.length; i++) {
if (f.func(vals[i], v)) {
count++;
}
}
return count;
}
public …
Run Code Online (Sandbox Code Playgroud) 对对象使用“空检查”选项克隆不同类型的对象。
class A{ C cObj, List<B> bList;}
class B{ C cObj; List<C> cList;}
class C { String label; String value;}
class D{ String name; String age; String addressCode;}
Run Code Online (Sandbox Code Playgroud)
映射A-> D
d.setAddessCode(A.getBlist().get(0).getcList().get(0).getValue());
Run Code Online (Sandbox Code Playgroud)
如何使用Java 8可选检查null
A.getBlist().get(0).getcList().get(0).getValue()
Run Code Online (Sandbox Code Playgroud)
我试过了
d.setAddessCode(Optional.ofNullable(A).map(A::getBList).map(Stream::of).orElseGet(Stream::empty).findFirst().map(B::getCList).map(Stream::of).orElseGet(Stream::empty).findFirst().map(C::getValue).orElse(null)));
Run Code Online (Sandbox Code Playgroud)
我如何才能一起检查列表和值中的null。
POST请求
http:// localhost:9278 / submitEnrollment
封装外部SOAP调用的Spring Boot应用程序执行以下操作:
{
"timestamp": 1439480941381,
"status": 401,
"error": "Unauthorized",
"message": "Full authentication is required to access this resource",
"path": "/submitEnrollment"
}
Run Code Online (Sandbox Code Playgroud)
这似乎不是正常现象,我想知道我需要放松/禁用哪些Spring Boot配置才能阻止此客户端身份验证。
以下是相关的代码段:
应用程序的配置(需要通过SSL发送安全的SOAP调用所需的所有必要操作,并会影响网络层):
@Configuration
@ComponentScan({"a.b.c.d", "com.submit.enrollment"})
@PropertySource("classpath:/submit-enrollment.properties")
public class SubmitEnrollmentConfig {
@Value("${marshaller.contextPaths}")
private String[] marshallerContextPaths;
@Value("${default.Uri}")
private String defaultUri;
@Bean
public FfmSoapClient connectivityClient() throws Throwable {
FfmSoapClient client = new FfmSoapClient();
client.setWebServiceTemplate(webServiceTemplate());
return client;
}
@Bean
public KeyStore keyStore() throws Throwable {
KeyStoreFactoryBean keyStoreFactory = new KeyStoreFactoryBean();
keyStoreFactory.setPassword("!zxy!36!");
keyStoreFactory.setLocation(new ClassPathResource("zxy.jks"));
keyStoreFactory.setType("jks");
keyStoreFactory.afterPropertiesSet();
return …
Run Code Online (Sandbox Code Playgroud) security configuration web spring-boot spring-restcontroller
我刚刚开始使用 Armeria 并努力完全理解一些事情。
我实现DecoratingHttpServiceFunction
是为了向具有 Hibernate 会话的服务提供请求。
@Override
public HttpResponse serve(HttpService delegate, ServiceRequestContext ctx, HttpRequest req) {
... // setup session for the request context
HttpResponse response = delegate.serve(ctx, req);
... // close session
return response;
}
Run Code Online (Sandbox Code Playgroud)
但显然会话在服务实际被调用之前关闭,并且返回的请求delegate.serve
是DeferredHttpResponse
. 我的方法是完全错误还是有更好的方法来做我想做的事?
我在基准测试中注意到,Java中的算术复合运算符总是优于常规赋值:
d0 *= d0; //faster
//d0 = d0 * d0; //slower
d0 += d0; //faster
//d0 = d0 + d0; //slower
Run Code Online (Sandbox Code Playgroud)
有人可以对上述观察结果发表评论并解释原因.我假设字节码级别的一些差异是加速的原因吗?先感谢您.
这是我的基准,更全面:
public long squaring() {
long t0 = System.currentTimeMillis();
double d0 = 0;
for (int k = 0; k < 100_000_000; k++){
//check bytecode for below to see why timing differs
d0 *= d0; //faster
//d0 = d0 * d0; //slower
}
long t1 = System.currentTimeMillis();
long took = (t1 - t0);
System.out.println("took: "+took + " …
Run Code Online (Sandbox Code Playgroud) java ×3
java-8 ×2
armeria ×1
java-stream ×1
lambda ×1
object ×1
optional ×1
performance ×1
security ×1
spring-boot ×1
syntax ×1
web ×1