• class.getName()与class.getSimpleName()的区别


    转载自https://blog.csdn.net/Aquarius_Seven/article/details/51916154

    Class.getName():以String的形式,返回Class对象的“实体”名称;

    Class.getSimpleName():获取源代码中给出的“底层类”简称。

    单看这种书面文字的话,可能有人还是不明白他们的区别,下面我就将通过代码以及图片的形式,让大家直观地看到它们的区别,代码很简单,结果也很简单。

    代码如下:

    [java] view plain copy
     
    1. public class Main {  
    2.       
    3.     private static final String TAG1 = Main.class.getName();  
    4.     private static final String TAG2 = Main.class.getSimpleName();  
    5.       
    6.     public static void main(String[] args) {  
    7.         System.out.println("getName ----- " + TAG1 + " " + "getSimpleName ----- " + TAG2);  
    8.     }  
    9. }  

    结果图片如下:

    如上图所示,我们可以很清晰明了地看出它们的区别:

    getName ----“实体名称” ---- com.se7en.test.Main

    getSimpleName ---- “底层类简称” ---- Main

  • 相关阅读:
    codeforces 189A
    hdu 2085
    hdu 2083
    cf 1237 C2. Balanced Removals (Harder)
    cf 1244 D. Paint the Tree
    cf 1241 E. Paint the Tree(DP)
    cf 1241 D. Sequence Sorting(思维)
    cf1228 D Complete Tripartite(哈希)
    Windows10 与 WSL(Ubuntu)的文件互访
    Ubuntu下运行python文件
  • 原文地址:https://www.cnblogs.com/yfafa/p/8629081.html
Copyright © 2020-2023  润新知