「Java入門」getName(), getSimpleName(), getCanonicalName()のサンプル

サンプルコード

package procft;

public class ChangFaEmployee {

	public static void main(String[] args) {
		System.out.println(" Name      : " + ChangFaEmployee.class.getName());
		System.out.println(" SimpleName : " + ChangFaEmployee.class.getSimpleName());
		System.out.println(" Canonical Name: " + ChangFaEmployee.class.getCanonicalName());
		System.out.println("Outer Anonymous Class");
		new Object() {
			public void className() {
				System.out.println(" Name      : " + getClass().getName());
				System.out.println(" SimpleName : " + getClass().getSimpleName());
				System.out.println(" CanonicalName : " + getClass().getCanonicalName());
			}
		}.className();

	}

}

実行結果
 Name      : procft.ChangFaEmployee
 SimpleName : ChangFaEmployee
 Canonical Name: procft.ChangFaEmployee
Outer Anonymous Class
 Name      : procft.ChangFaEmployee$1
 SimpleName : 
 CanonicalName : null

Java

Posted by arkgame