我想要实现的是对我的数据库表的一个很好的抽象。我正在寻找的结果是能够做到这一点:
System.out.println(Table.Appointment); // prints the name of the table
System.out.println(Table.Appointment.ID); // prints the name of the column
这是我已经接近的内容,但字段似乎优先于静态内部类。
public class Table {
// attempt to allow 'Table.Appointment' to resolve to a String
public static final Table Appointment = new Table("Appointment");
// attempt to give access to column names within the table,
// these class names should be the same as its name field above.
public static final class Appointment{
public static final String ID = "AppointmentId";
};
private String name;
private Table(String name){ this.name = name; }
public String toString() { return name; }
}
这真的可以实现吗?