`
samjavaeye
  • 浏览: 187715 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Avoid Literals In If Condition

 
阅读更多
【原因分析】
在条件判断语句中使用了硬编码的字面值,例如:
if (!"0".equals(retCode))
  
【影响分析】
这种硬编码的字面值不容易理解其含义,进而影响对逻辑表达式的理解。另外硬编码的字面值也容易在代码中重复出现,给代码的维护增加难度。
 
【修改建议】
建议修改。将硬编码的字面值定义成静态变量或私有的成员变量。例如:
private String CODE_ZERO = "0";
if (!this.CODE_ZERO.equals(retCode))
 
分享到:
评论

相关推荐

    Java Data Types & Literals | 数据类型 和 字面量

    NULL 博文链接:https://wuaner.iteye.com/blog/1668172

    babel-plugin-transform-object-literals:用JSON.parse()替换可序列化的对象文字

    npm install -- save - dev babel - plugin - transform - object - literals 然后将transform-object-literals添加到您的.babelrc : { " plugins " : [ " transform-object-literals " ] } 尝试 cd examples ...

    《Programming in Java Second Edition》高清完整英文PDF版

    Java 7 includes support for strings in switch statements, try-with-resources statement, improved multi-catch, binary numeric literals, numeric literals with underscores, new APIs in NIO like Path and...

    unidac74.12d26-pro.rar for delphi 10.3.1

    Universal Data Access Components History unidac@devart.com 7.4.12 21-Jan-19 Bug with using the datetime literals in SQL statements in TVirtualQuery is fixed Bug with AV failure in the Refresh method ...

    EditPlus.5.0.777 64位 中文版

    - Fixes an issue where #AUTOCASE=y in the syntax file didn't work if auto completion was off. - Allows Ctrl+Shift+Up/Down instead of Ctrl+Alt+Up/Down to avoid hotkey conflict. - Fixes an issue where ...

    Pro CDI 2 in Java EE 8.pdf

    In Pro CDI 2 in Java EE 8, use CDI and the CDI 2.0 to automatically manage the life cycle of your enterprise Java, Java EE, or Jakarta EE application’s beans using predefined scopes and define custom...

    units_literals:用于升压单元的用户定义文字

    // 9.11 皮秒这些是在boost::units::literals命名空间中的literals.hpp头文件中定义的。常数定义了各种常量(使用用户定义的单位文字)。 const auto c = 299792458.0_m / 1_s; // 真空中的光速const auto k = R / ...

    minify-html-literals:缩小HTML模板文字字符串

    minify-html-literals 缩小JavaScript模板文字字符串中HTML标记。为什么? 模板文字通常在JavaScript中用于编写HTML和CSS标记(例如 )。 该库允许开发人员缩小通常被JavaScript缩小程序忽略的标记。用法import { ...

    Devart_UniDAC_7.4.12_Professional_D7-D10.3_Rio_Full_Source_Code

    Bug with using the datetime literals in SQL statements in TVirtualQuery is fixed Bug with AV failure in the Refresh method in RAD Studio 10.2 Tokyo on Linux is fixed Oracle data provider Bug with ...

    JSP Simple Examples

    We use the if condition to check if the particular condition is true then it should perform a certain task, and if a particular condition is not true then it should do some other tasks. ...

    Options and Derivatives Programming in C++

    New features introduced in the C++11 and C++14 standard are also covered: lambda functions, automatic type detection, custom literals, and improved initialization strategies for C++ objects. ...

    C#_7 Quick Syntax Reference, 2nd Edition--2018

    A Pocket Guide to the Language, APIs, and Library What You Will Learn Discover what’s new in C# 7.3 and ... Use the new numeric literals found in C# 7.3 to improve readability for numeric constants

    time-literals:jsr-310(java.time)实体的Clojure(Script)标记文字

    时间文学一个Clojure(Script)库,它为jsr-310域中的对象提供带标记的文字,在jvm上是java.time库中的对象,而在... 它捆绑了该库,并且默认情况下启用time-literals打印。用法莱恩/靴子 该库包含魔术文件data_reader

    Programming in Objective-C 4th Edition

    Compound Literals 293 The goto Statement 294 The null Statement 294 The Comma Operator 294 The sizeof Operator 295 Command-Line Arguments 296 How Things Work 298 Fact #1: Instance Variables Are Stored...

    visual assist 1640

    (General release.) Fixed spurious coloring of string literals in VC6. (case=16454) 7565 Fixed Asian character display corruption in VC6. (case=16737) 7782 Fixed spurious coloring of ...

    C.in.a.Nutshell.2nd.Edition.1491904755

    With the new edition of this classic book, you'll learn the 2011 standard C language in easy, exact terms. Every C programmer who needs to know the effects of an unfamiliar function, or to understand ...

    rollup-plugin-minify-html-literals:汇总插件可最小化HTML模板文字字符串

    import minifyHTML from 'rollup-plugin-minify-html-literals' ;import { uglify } from 'rollup-plugin-uglify' ;export default { entry : 'index.js' , dest : 'dist/index.js' , plugins : [ minifyHTML ( ) , ...

    Python library

    For these types, the Python language core defines the form of literals and places some constraints on their semantics, but does not fully define the semantics. The library also contains built-in ...

    Autosar EXP ModemanagementGuide

    an enumeration groups literals. In the given example this could be the ModeDeclarationGroup ECUMODE. For each ModeDeclarationGroup an InitialMode has to be defined, which is assigned to the variable ...

    Rediscovering JavaScript

    Learn practical tips to apply the elegant parts of the language and the gotchas to avoid. JavaScript is a black swan that no one, including the author of the language, thought would become a popular ...

Global site tag (gtag.js) - Google Analytics