广告
返回顶部
首页 > 资讯 > 移动开发 >Android Notes思码逸问题处理记录
  • 201
分享到

Android Notes思码逸问题处理记录

2024-04-02 19:04:59 201人浏览 泡泡鱼
摘要

目录前言Static non-final field names should comply with a naming conventionJump statements shou

前言

从年初开始,我司便开始将思码逸作为了 OKR 必选项,从开始的抵触,到现在的坦然,也算是被锤之路...

简单附上对应问题解决的思路或者方式,以便于小伙伴类似直接操作。

个人对于思码逸的看法,其实多属于还是基于阿里一些规范,虽说有点繁琐,甚至有些许难受,长远来看,未尝不是一件好事儿。

点滴做起,基于思码逸,一起来改善自己代码吧~

先附上阿里编码指南:

p3c

Static non-final field names should comply with a naming convention

提示如下:

大概的意思就是静态非 final 命名不规范,这里直接追加 final 即可。

Jump statements should not be redundant

问题代码如下:

提示如下:

Jump statements such as return and continue let you change the default flow of program execution, but jump statements that direct the control flow to the original direction are just a waste of keystrokes.

Fix:

  • 独立出来,不满足条件直接 return 即可。

Deprecated code should be removed

问题代码如下:

提示如下:

  • 此规则旨在用作跟踪标记为已弃用的代码的一种方式。弃用的代码最终应该被删除。

Fix:

  • 历史包袱,只能看具体代码,具体分析,如果有替代则使用推荐的。(真是一句废话...

Unused method parameters should be removed

问题代码如下:

提示如下:

  • 未使用的参数具有误导性。无论传递给此类参数的值如何,行为都是相同的。

附上对应代码图:

当然以下是一些例外情况:

  • that are annotated with @javax.enterprise.event.Observes
  • in overrides and implementation methods
  • in interface default methods
  • in non-private methods that only throw or that have empty bodies
  • in annotated methods, unless the annotation is @SuppressWarning("unchecked") or @SuppressWarning("rawtypes"), in which case the annotation will be ignored
  • in overridable methods (non-final, or not member of a final class, non-static, non-private), if the parameter is documented with a proper javadoc.

[p3c]To judge the equivalence of floating-point numbers, == cannot be used for primitive types, while equals cannot be used for wrapper classes.

问题代码如下:

提示如下:

  • 浮点数之间的等值判断,基本数据类型不能用 == 来比较,包装数据类型不能用 equals 来判断

如何 Fix?

  • 本质理解为一个精度问题,例如某些情况下 0.1 和 0.111 是相等的。

只需要将原本的 == 替换为 Float.compare(a,b) == 0 即可。

Others 知识点回顾:

回顾基本数据类型和包装类型:

基本类型包装类型
booleanBoolean
charCharacter
intInteger
byteByte
shortShort
longLong
floatFloat
doubleDouble

而它们之间区别如下:

  • 基本类型均有默认值,而包装类型初始化则是 NULL。也就是说基本类型可以用直接使用,而包装类型必须实例化后才可以使用;
  • 包装类型实际是对象的引用,new 一个包装类型的时候,实际上生成了一个指针指向此对象,而基本类型则事直接存储数据值;

这里额外回顾下 == 和 equals 区别吧:

  • == 对于基本类型来说是比较值,对于引用类型来说则是比较引用地址;
  • equals 默认情况下是比较引用地址,只是很多类重写了 equals 方法,比如 String、Integer 等把它变成了比较值,所以说一般情况下 equals 比较的是值是否相等。

THK

  • 你真的懂 == 和 equals 的区别吗?

以上就是Android Notes思码逸问题处理记录的详细内容,更多关于Android Notes思码逸问题处理的资料请关注编程网其它相关文章!

--结束END--

本文标题: Android Notes思码逸问题处理记录

本文链接: https://www.lsjlt.com/news/169047.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作