本文演示java注解的使用
1. getDeclaredFields方法
这个方法返回当前对象中的声明的Filed数组,只返回当前类,不会返回父类的Field.
public class News extends Article { public News(int id, Date createDate, Date modifyDate, String title, String content, boolean isPublication) { super(id, createDate, modifyDate, title, content, isPublication); } }
public class Article extends BaseEntry { protected String title;// 消息标题 protected String content;// 消息内容 protected boolean isPublication; // 是否已发布 public Article() { } public Article(int id, Date createDate, Date modifyDate, String title, String content, boolean isPublication) { super(id, createDate, modifyDate); this.title = title; this.content = content; this.isPublication = isPublication; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public boolean isPublication() { return isPublication; } public void setPublication(boolean isPublication) { this.isPublication = isPublication; } }
public class BaseEntry { protected int id;// ID protected Date createDate;// 创建日期 protected Date modifyDate;// 修改日期 public BaseEntry() { } public BaseEntry(int id, Date createDate, Date modifyDate) { this.id = id; this.createDate = createDate; this.modifyDate = modifyDate; } public BaseEntry( Date createDate, Date modifyDate) { this.createDate = createDate; this.modifyDate = modifyDate; } public int getId() { return id; } public void setId(int id) { this.id = id; } public Date getCreateDate() { return createDate; } public void setCreateDate(Date createDate) { this.createDate = createDate; } public Date getModifyDate() { return modifyDate; } public void setModifyDate(Date modifyDate) { this.modifyDate = modifyDate; } }