「Java」getName()、getSimpleName()とgetCanonicalName()の使い方

javaコード
package cftj;

public class ChangfaTunClassDemo {

public static void main(String[] args) {
System.out.println(“外部クラス");
System.out.println(" Name:" + ChangfaTunClassDemo.class.getName());
System.out.println(" Simple: " + ChangfaTunClassDemo.class.getSimpleName());
System.out.println(" Canonical: " + ChangfaTunClassDemo.class.getCanonicalName());
System.out.println(“匿名クラス");
new Object() {
public void className() {
System.out.println(" Name : " + getClass().getName());
System.out.println(" Simple: " + getClass().getSimpleName());
System.out.println(" Canonical: " + getClass().getCanonicalName());
}
}.className();

}
}
結果
外部クラス
Name:cftj.ChangfaTunClassDemo
Simple: ChangfaTunClassDemo
Canonical: cftj.ChangfaTunClassDemo
匿名クラス
Name : cftj.ChangfaTunClassDemo$1
Simple:
Canonical: null

Java

Posted by arkgame