在Java 8中,方法可以创建为Lambda表达式,并且可以通过引用传递(通过一些工作).有大量的在线示例,lambdas被创建并与方法一起使用,但没有关于如何使用lambda作为参数的方法的示例.那是什么语法?
MyClass.method((a, b) -> a+b);
class MyClass{
//How do I define this method?
static int method(Lambda l){
return l(5, 10);
}
}
Run Code Online (Sandbox Code Playgroud) 我有两个JDK,用于Java 6和7.
我想用两者构建我的项目.最初我们只针对1.6构建.我在项目设置中看到我可以选择1.5,1.6 1.7作为编译器级别.
如何将这些选项添加到IDE中?我从未安装过Java 1.5.假设我想要Java 1.4.如何让它出现在列表中?我在IDE首选项中添加了两个不同的JRE,但这些不是下拉列表中显示的内容.
我有以下请求处理程序来保存汽车.我已经证实,当我使用例如cURL时,这是有效的.现在我想用Spring MVC Test对方法进行单元测试.我曾尝试使用fileUploader,但我无法让它运行起来.我也没有设法添加JSON部分.
我如何使用Spring MVC Test对此方法进行单元测试?我无法找到任何这方面的例子.
@RequestMapping(value = "autos", method = RequestMethod.POST)
public ResponseEntity saveAuto(
@RequestPart(value = "data") autoResource,
@RequestParam(value = "files[]", required = false) List<MultipartFile> files) {
// ...
}
Run Code Online (Sandbox Code Playgroud)
我想为我的自动+一个或多个文件上传一个JSON表示.
我会在正确的答案中加上100分!
以下是代码段; 基本上,当错误代码不是200时,我试图传播异常.
ResponseEntity<Object> response = restTemplate.exchange(url.toString().replace("{version}", version),
HttpMethod.POST, entity, Object.class);
if(response.getStatusCode().value()!= 200){
logger.debug("Encountered Error while Calling API");
throw new ApplicationException();
}
Run Code Online (Sandbox Code Playgroud)
但是,如果来自服务器的500响应,我将获得异常
org.springframework.web.client.HttpServerErrorException: 500 Internal Server Error
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:94) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
Run Code Online (Sandbox Code Playgroud)
我真的需要在try中包装其余的模板交换方法吗?那么代码的目的是什么?
如果我将@Builder添加到类中.构建器方法已创建.
Person.builder().name("john").surname("Smith").build();
Run Code Online (Sandbox Code Playgroud)
我有一个要求需要特定字段的要求.在这种情况下,名称字段是必需的,但姓氏不是.理想情况下,我想宣布它是这样的.
Person.builder("john").surname("Smith").build()
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何做到这一点.我尝试将@Builder添加到构造函数中,但它不起作用.
@Builder
public Person(String name) {
this.name = name;
}
Run Code Online (Sandbox Code Playgroud) 我的JDK 9 + 181 Spring Boot 2.0.0.BUILD-SNAPSHOT CLI应用程序在启动时显示此警告:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (jar:file:/home/jan/src/fm-cli/target/fm-cli-0.1.0-SNAPSHOT.jar!/BOOT-INF/lib/spring-core-5.0.0.RELEASE.jar!/) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils$1
Run Code Online (Sandbox Code Playgroud)
这是一个控制台应用程序,所以我需要禁用此警告 - 我该怎么做?
注意:此问题询问如何禁用Spring触发此警告的具体问题; 它不是JDK9的副本:发生了非法的反射访问操作.org.python.core.PySystemState,用于处理不同库中的类似症状.
截至今天上午,具有角CLI的1.0.0-beta.14我ng new try3和ng serve并得到以下错误:
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration has an unknown property 'tslint'. These properties are valid:
object { amd?, bail?, cache?, context?, devServer?, devtool?, entry, externals?, loader?, module?, name?, dependencies?, node?, output?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }
- configuration.module has an unknown property 'preLoaders'. These properties are valid:
object { …Run Code Online (Sandbox Code Playgroud) 我在基于Lombok的POJO中有一个自定义setter:
@Data
@Builder
public class User {
private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder();
private String password = null;
public void setPassword(String password) {
Assert.notNull(password);
this.password = ENCODER.encode(password);
}
Run Code Online (Sandbox Code Playgroud)
但是当我使用Lombok生成的构建器时:
User user = User.builder()
.password(password)
.build();
Run Code Online (Sandbox Code Playgroud)
我的自定义setter未被调用,因此密码未被编码.这让我很伤心.
当然,直接使用我的自定义setter时会调用它:
public void changePassword(String password, User user) {
user.setPassword(password);
}
Run Code Online (Sandbox Code Playgroud)
如果让Lombok的构建器使用我的自定义setter,我该怎么办?
我试图pg_dump在Debian上运行的PostgreSQL 9.0.4服务器上执行,我收到以下错误:
./pg_dump: error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
libpq.so.5是一个链接,libpq.so.5.3如下所示
lrwxrwxrwx 1 root root 12 Jun 27 16:24 libpq.so.5 -> libpq.so.5.3
-rwxr-xr-x 1 root root 180749 Jun 21 02:43 libpq.so.5.3
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
如果bean中的所有对象都实现了Serializable接口,那么会BeanUtils.cloneBean()进行深层复制吗?
java ×6
spring ×3
lombok ×2
angular ×1
angular2-cli ×1
debian ×1
deep-copy ×1
eclipse ×1
java-8 ×1
java-9 ×1
java-module ×1
javabeans ×1
lambda ×1
postgresql ×1
rest ×1
resttemplate ×1
spring-boot ×1
spring-mvc ×1
unit-testing ×1