简体   繁体   English

为什么这些字符串比较在 java 中有不同的结果?

[英]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.

相关问题 为什么在Java中字符串比较结果没有显示0、1或-1? - Why string comparison results are not printing 0,1, or -1 in Java? 为什么在Java中使用string.equals()方法将字符串与字符串进行比较,对使用相似语法的2个不同查询产生不同的结果? - Why is my string to string comparison In Java using the string.equals() method yeilding different results on 2 different queries with similar syntax? 字符串比较-JDK版本产生不同的结果 - String comparison - JDK versions produce different results 为什么 Java 字符串比较在 Java 15 和 Java 11 中表现不同? - Why does a Java string comparison behave different in Java 15 and Java 11? Java:将数字和字符串转换为十六进制会返回不同的结果。 为什么? - Java: converting numbers and string to hex returns different results. Why? Java 字符串比较,按字母顺序打印两个不同的字符串输入 - Java string comparison, printing two different string inputs into alphabetical order 相同的正则表达式在Java和Python中有不同的结果 - Same regex have different results in Java and Python 我在for和stream中有不同的结果,为什么? - I have different results in for and stream, why? 为什么我使用String.intern()与在Java中传递String对象获得不同的结果? - Why do I get different results with String.intern() vs. passing String object in Java? 为什么我对相同文本的 python 和 java base64 编码有不同的结果? - Why I have different results for python and java base64 encode for the same text?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM