假设我有一个有很多不同领域的类.这个类是DTO,出于测试目的,我不关心实际值,只是它存在.是否有任何工具可以遍历所有字段并设置基元,0表示Number(0.0表示Float,Double,0表示整数,0L表示Long,但默认情况下不为null),类似于"test"for String?
此外,我希望该工具填充集合(列表,集,地图).
如何模拟修改私有变量的私有方法?
class SomeClass{
private int one;
private int second;
public SomeClass(){}
public int calculateSomething(){
complexInitialization();
return this.one + this.second;
}
private void complexInitialization(){
one = ...
second = ...
}
}
Run Code Online (Sandbox Code Playgroud) Cobnsider以下代码:
public static void main (String[] args) {
Map<Number, String> map = new HashMap<Number, String>();
map.put(1L, "test");
System.out.println(map.get(1));
}
Run Code Online (Sandbox Code Playgroud)
为什么HashMap.get返回null?O_o它必须为hashCode函数返回1的任何对象返回值,不是吗?
更新
问题是Map接口接收Object,而不是参数化类型.所以我期望任何对象都可以是一个键,但HashMap实现检查类型与equals,这对我来说是令人惊讶的.
而自动装箱不是问题.我知道,1成为Integer,1L成为Long.但是它们具有相同的哈希码.因此我认为任何实现Map#get都应返回具有相同哈希码的任何Object的值.
我在“程序文件”目录中安装了一个 git,我没有修改它的权限(只能读取)。但我想放一些新的钩子。有没有办法在命令行中调用git并为 hooks 目录指定新路径?
考虑下面的代码:
val first = ...
val second = ...
val third = ...
val fours = ...
first match {
case "someString" => second match {
case s:String => third match {
case MyEnum.A => //some logic
case MyEnum.B => fours match {
case Some(old:String) => //some other logic
case default=> defaulLogic
}
case default=> defaulLogic
}
case default=> defaulLogic
}
case default=> defaulLogic
}
private def defaulLogic()= {
//log error here
}
Run Code Online (Sandbox Code Playgroud)
有没有办法将case default逻辑放在一个地方而不是在每个模式匹配中复制它?
注意
只有顶部的match-case …
假设我使用这样的代码:
ElasticClient client = ...
client.execute{search in "places"->"cities" query "paris" start 5 limit 10}
Run Code Online (Sandbox Code Playgroud)
如何查看已向Elasticsearch发送了哪些json请求?
考虑一下数组:
new Pattern[] {Pattern.compile("\\["),Pattern.compile("\\]") };
Run Code Online (Sandbox Code Playgroud)
Intellij IDEA告诉我这\\是多余的,并告诉我将其替换为]例如结果是:
new Pattern[] {Pattern.compile("\\["),Pattern.compile("]") };
Run Code Online (Sandbox Code Playgroud)
为什么第一个Pattern.compile("\\[")是\\好的,但是第二个是多余的?
这是有关LogGroup通过 Cloud Formation创建 Cloud Watch 的文档。他们说:
保留天数
日志事件保留在 CloudWatch Logs 中的天数。当日志事件过期时,CloudWatch Logs 会自动将其删除。有关有效值,请参阅 Amazon CloudWatch Logs API 参考中的 PutRetentionPolicy。
要求:否
因此,如果我创建没有RetentionInDays参数的LogGroup,Cloud Watch 会永远保留这些日志吗?或者RetentionInDays他们默认使用什么值?
考虑一个代码:
package com.hellokoding.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class WebApplication extends SpringBootServletInitializer {
@Bean
@ConditionalOnProperty(prefix = "config.prefix", name = "name", value = "SOMEVALUE", matchIfMissing = true)
public BeanOne beanOne() {
System.out.println("ok");
return new BeanOne();
}
@Bean
@ConditionalOnProperty(prefix = "config.prefix", name = "name", value = "OTHERVALUE")
public BeanTwo beanTwo() {
System.out.println("ok");
return new BeanTwo();
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(WebApplication.class);
}
public static void main(String[] args) throws Exception { …Run Code Online (Sandbox Code Playgroud) 考虑一个片段:
---
version: '3.4'
services:
app:
image: my_image
command: ["sleep", "60s", "&&", "my_command"]
Run Code Online (Sandbox Code Playgroud)
给我:
sleep: invalid time interval ???my_command??™
Try 'sleep --help' for more information.
Run Code Online (Sandbox Code Playgroud)
怎么了?为什么会这样?
Docker version 19.03.2, build 6a30dfc
Host OS - windows 10
Run Code Online (Sandbox Code Playgroud)