Java 内部类实例化

Java内部类实例化写法感觉好怪异:

public class ComboboxResponse {

	private List<ComboboxItem> dataItems = new ArrayList<ComboboxItem>();
	
	
	public List<ComboboxItem> getDataItems() {
		return dataItems;
	}

	public void setDataItems(List<ComboboxItem> dataItems) {
		this.dataItems = dataItems;
	}


	public class ComboboxItem{
		String id;
		
		String text;
		
		public ComboboxItem(){}
		
		public ComboboxItem(String id, String text){
			this.id = id;
			this.text = text;
		}		
		
		public String getId() {
			return id;
		}

		public void setId(String id) {
			this.id = id;
		}

		public String getText() {
			return text;
		}

		public void setText(String text) {
			this.text = text;
		}
	}	
}


内部类的初始化是这样的。

ComboboboxResponse response = new ComboboxResponse();
ComboboxItem ci = response.new ComboboxItem("key", "value");

这样写是错误的:

ComboboxItem ci = new ComboboxItem("key", "value");

这样写也是错误的:

ComboboxItem ci = ComboboxResponse.ComboboxResponse();


posted @ 2017-07-24 16:29  hongweigg  阅读(10)  评论(0编辑  收藏  举报