android DefaultLocale: Implied default locale in case conversion

最近使用link的检查时,发现有这个警告,记录一下这个警告的解决办法。

 ../../src/main/java/com/fm/view/KeyboardUtil.java:140: Implicitly using the default locale is a common source of bugs: Use toLowerCase(Locale) instead

 137 
 138    private boolean isword(String str) {
 139        String wordstr = "abcdefghijklmnopqrstuvwxyz";
 140        if (wordstr.indexOf(str.toLowerCase()) > -1) {

 141            return true;
 142        }

Priority: 6 / 10
Category: Correctness
Severity: Warning
Explanation: Implied default locale in case conversion.
Calling String#toLowerCase() or #toUpperCase() without specifying an explicit locale is a common source of bugs. The reason for that is that those methods will use the current locale on the user's device, and even though the code appears to work correctly when you are developing the app, it will fail in some locales. For example, in the Turkish locale, the uppercase replacement for i is not I.

If you want the methods to just perform ASCII replacement, for example to convert an enum name, call String#toUpperCase(Locale.US) instead. If you really want to use the current locale, call String#toUpperCase(Locale.getDefault()) instead. 

按照提示使用toLowerCase(Locale.getDefault())替换就好。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值