[英]Why these String comparison have different results in java?
This throws IllegalStateException, the checkArgument method is Google's com.google.common.base.Preconditions.checkArgument
:这会抛出 IllegalStateException,checkArgument 方法是 Google 的
com.google.common.base.Preconditions.checkArgument
:
checkArgument(apikey.equals("3243442-bb73-123-421f-sfsglk"), "Wrong api key.");
vs.对比
This gets into the if block:这进入 if 块:
if (apikey.equals("3243442-bb73-123-421f-sfsglk")) {
// do something
}
The apikey value is stored in the Spring boot config file and is retrieved by @Value("${apikey}")
. apikey 值存储在 Spring 引导配置文件中,并由
@Value("${apikey}")
检索。
I know this is not how API keys are done, but I needed something quick for a small side project to test something.我知道这不是 API 密钥的完成方式,但我需要一些快速的小项目来测试一些东西。
Spring-Boot
does not trim off the trailing whitespaces in the config files. Spring-Boot
不会修剪配置文件中的尾随空格。
If you are sure the key is correct in the config file, this should pass the check:如果您确定配置文件中的密钥是正确的,则应该通过检查:
checkArgument(apikey.trim().equals("3243442-bb73-123-421f-sfsglk"), "Wrong api key.");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.