Best way to define typesafe ids?

HI,

I have different tables with BeanItemContainer. I’d like to define the property id’s inside the bean for type safety. But how could I do this most efficient?

I came up with an enum having a String so far, but are there better ways?


class MyBean {
        private int id;
        private String name;

	public enum Fields {
		ID("id"), NAME("name");
		
		private String string;
		
		private Fields(String string) {
			this.string = string;
		}
		
		public String toString() {
			return string;
		}
	}
}

//usage
table.setVisibleColumns(new String[] {MyBean.Fields.NAME.toString()});

How would you do this?