`
samjavaeye
  • 浏览: 194601 次
  • 性别: 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 | 数据类型 和 字面量

    字面量(Literals)则是程序中直接写出来的值,它们可以是数字、字符串、字符或者布尔值。例如,`5`是一个整数字面量,`"Hello"`是一个字符串字面量,`'A'`是一个字符字面量,而`true`则代表布尔字面量。 在`Data...

    C++基础知识-String 和 character literals.pdf

    C++基础知识——String 和 character literals

    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 ...

    C PROGRAMMING TUTORIAL

    C is a general-purpose, procedural computer programming language developed in the early 1970s by Dennis Ritchie at Bell Labs. It is one of the most widely used programming languages and serves as the ...

    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 ...

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

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

    HP_Vertica_7.1.x_SQL_Reference_Manual

    - **Single Quotes in a String**: If a string literal contains a single quote, it must be escaped with another single quote or using escape characters. - **Standard Conforming Strings and Escape ...

    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. ...

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

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

    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 ( ) , ...

Global site tag (gtag.js) - Google Analytics