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

Multiple String Literals

 
阅读更多
【原因分析】
在同一个java文件,相同的字符串出现了多次。例如:
public String doAdd(HttpServletRequest request) {
        String name = request.getParameter("name");
        ......
}
public String doUpdate(HttpServletRequest request) {
        String newName = request.getParameter("name");
        ......
}
 
【影响分析】
重复的代码会增加维护难度,如果字符串内容变更了,则需要同时修改多处。
 
【修改建议】
将相同的字符串定义成一个常量。例如:
private static final String PARAM_NAME = "name";
public String doAdd(HttpServletRequest request) {
        String name = request.getParameter(PARAM_NAME);
        ......
}
public String doUpdate(HttpServletRequest request) {
        String newName = request.getParameter(PARAM_NAME);
        ......
}
分享到:
评论

相关推荐

    HP_Vertica_7.1.x_SQL_Reference_Manual

    - **String Literals**: These represent text values and can be character string literals, dollar-quoted string literals, Unicode string literals, and VARBINARY string literals. - **Character String ...

    VA_X_Setup1940

    Surround With feature is no longer invokable within comments, string literals, and tags in XML/HTML/XAML. (case=74045) Fix for Visual Studio reporting an exception when scrolling quickly through ...

    EXECUTABLE AND LINKABLE FORMAT

    - **.rodata**: Contains read-only data such as string literals and constant values. - **.comment**: Contains the name and version of the compiler used to create the file. - **.debug**: Contains ...

    python3.6.5参考手册 chm

    PEP 498: Formatted string literals PEP 526: Syntax for variable annotations PEP 515: Underscores in Numeric Literals PEP 525: Asynchronous Generators PEP 530: Asynchronous Comprehensions PEP 487:...

    ARM® Compiler v5.06 for µVision® armasm User Guide

    7.13 String literals 7.14 Numeric expressions 7.15 Syntax of numeric literals 7.16 Syntax of floating-point literals 7.17 Logical expressions 7.18 Logical literals 7.19 Unary operators 7.20 Binary ...

    JSP Simple Examples

    Suppose if we have a declare an array of type String, then it will store only the String value not any other data type. When we have a closely related data of the same type and scope, it is better to...

    JDK1.7免安装版

    - **二进制字面量与下划线分隔符(Binary Literals & Underscores in Numeric Literals)**: 支持二进制字面量(如`0b1010`)以及数字中间使用下划线提高可读性(如`100_000`)。 2. **免安装版的使用** JDK 1.7...

    INTRODUCTION TO PYTHON SCRIPTING FOR MAYA ARTISTS.

    - **Don't Use Magic Numbers:** Replace numeric literals with named constants for clarity. **Comments** Comments help explain the purpose and functionality of code. Effective commenting enhances code ...

    acpi控制笔记本风扇转速

    produced when this parameter was a null string (""). Now, the original input filename is used as the AML output filename, with an ".aml" extension. Implemented a generic batch command mode for the ...

    Secrets of the JavaScript Ninja, 2nd Edition

    Template literals enhance string manipulation capabilities, making code more readable and concise. #### Function Parameters Function parameters in JavaScript have evolved with ES6, introducing rest ...

    node-ts-dedent:TypeScript软件包,可巧妙地修剪和去除多行字符串中的压痕

    TypeScript Dedent ... multiple lines. Luckily dedent is here to keep it readable without lots of spaces ending up in the string itself.` ) ; console . log ( dedent ` A string that gets so long y

    Addison.Wesley.C++.by.Dissection.2002.pdf

    - **Multiple Inheritance:** Discusses multiple inheritance. - **RTTI and Other Fine Points:** Explains run-time type identification and other advanced topics. - **Software Engineering: Inheritance and...

    C PROGRAMMING TUTORIAL

    ##### String literals Represent sequences of characters. - **Syntax:** `"Hello"`, `"World"`. ##### Defining Constants There are two ways to define constants in C. - **Using `#define`:** ...

    C++ 标准 ISO 14882-2011

    - 字面量(Literals)定义了在C++中表示数据值的各种方式。 3. 基本概念(Basic concepts) - 声明和定义(Declarations and definitions)解释了变量、函数等如何在程序中声明和定义。 - 单定义规则(One ...

    06 You Don't Know JS:ES6 & Beyond.pdf

    - 介绍SIMD(Single Instruction Multiple Data)技术及其在高性能计算中的应用。 - 分析SIMD如何加速向量运算。 通过以上章节的学习,读者能够全面了解ES6及其后续版本的新特性,并掌握如何有效地利用这些特性来...

    javascript权威指南(第六版)

    10.2 String Methods for Pattern Matching 259 10.3 The RegExp Object 261 11. JavaScript Subsets and Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 11.1 ...

    Google C++ International Standard.pdf

    5.13 Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 6 Basic concepts 39 6.1 Declarations and definitions . . . . . . . . . . . . . . . . . . . ...

Global site tag (gtag.js) - Google Analytics