/**
 * 
 * @author Zen Johnny
 *
 */
package com.cpms.test;

import java.lang.reflect.Field;
import java.util.List;

public class ReflectDemo {
	public static void clazz() {
		Person employee = new Person();
		Class<Person> clazz = (Class<Person>) employee.getClass();
		
		System.out.println("getCanonicalName: " + clazz.getCanonicalName());
		System.out.println("getName: " + clazz.getName());
		System.out.println("getSimpleName: " + clazz.getSimpleName());
		System.out.println("getTypeName: " + clazz.getTypeName());
	}
	
	public static void main(String args[]) {
		clazz();
	}
}

class Person{
	public String nickName;//public field
	private String realName;
	private int age;
	private List<String> friends;
	private double money; //no setter and getter
	
	public String getNickName() {
		return nickName;
	}
	public void setNickName(String nickName) {
		this.nickName = nickName;
	}
	public String getRealName() {
		return realName;
	}
	public void setRealName(String realName) {
		this.realName = realName;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public List<String> getFriends() {
		return friends;
	}
	public void setFriends(List<String> friends) {
		this.friends = friends;
	}
	
	@Override
	public String toString() {
		return "Person [nickName=" + nickName + ", realName=" + realName + ", age=" + age + ", friends=" + friends
				+ ", money=" + money + "]";
	}
}

  输出:

getCanonicalName: com.cpms.test.Person
getName: com.cpms.test.Person
getSimpleName: Person
getTypeName: com.cpms.test.Person

  

相关文章:

  • 2021-05-02
  • 2021-07-25
  • 2021-09-21
  • 2021-12-08
  • 2021-08-10
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-16
  • 2022-12-23
  • 2022-12-23
  • 2021-09-30
  • 2022-12-23
相关资源
相似解决方案