zoukankan      html  css  js  c++  java
  • Java 编码规范 StandardCharsets.UTF_8 三个方法 toString() name() displayName(),到底用哪个方法更合适?

    想用StandardCharsets.UTF_8 返回"UTF-8"这个字符,测试一下,三个方法toString() name() displayName(),均能返回"UTF-8",到底用哪个方法更健壮?

    public final String name()

    Returns this charset's canonical(正式的) name.
    =========================================
    public String displayName()

    Returns this charset's human-readable(便于人类可阅读的) name for the default locale.

    The default implementation of this method simply returns this charset's canonical name. Concrete subclasses of this class may override this method in order to provide a localized display name.
    ==========================================
    public final String toString()

    Returns a string describing this charset.

    ==========================================

    一分析,自然是name displayName比toString更合适,二选一,找区别自然选择name,因为我是要给程序传递参数,而不是输出给人机界面。

    另外,找了一个最好的例证,jdk有这样的用法:
     package java.util.zip;
    final class ZipCoder

      private ZipCoder(Charset cs) {
        this.cs = cs;
        this.isUTF8 = cs.name().equals(StandardCharsets.UTF_8.name());
      }

     这些自己更放心啦。








  • 相关阅读:
    Dropout:随机失活
    SGD的优化:SGD+Momentum、Nesterov Momentum、AdaGrad、 RMSProp、Adam
    Batch Normalization:批量归一化
    Zero-Centered:零均值化
    Activation Functions:激活函数
    Pooling Layer:池化层
    Convolution Layer:卷积层
    「狐狸」的模板库
    割点
    线段树基础知识详解
  • 原文地址:https://www.cnblogs.com/rgqancy/p/5280036.html
Copyright © 2011-2022 走看看