2
我使用EMF通過註釋的Java代碼如下生成方法返回EMF不可修改的列表
/**
* Adds the given type to this filter. Has no effect if the given type
* already belongs to this filter.
*
* @param type
* the type to add
* @model
*/
public void addEntityType(String type);
/**
* Returns the list of types belonging to this filter. Types are identified
* by there name.
*
* @return the list of types for this entity type filter
*
* @model
*/
public List<String> getEntityTypes();
/**
* Removes the given type from this filter. Has no effect if the given type
* doesn't belong to this filter.
*
* @param type
* the type to remove
* @model
*/
public void removeEntityType(String type);
從這個註釋的接口建立的Ecore和這個genmodel文件後,並生成代碼後getEntityTypes方法修改如下:
public EList<String> getEntityTypes();
爲了封裝的目的,我希望這個EList是不可修改的,因此接口客戶端的代碼只能通過添加和刪除方法來修改列表。
是否有任何干淨的方式來做到這一點,即修改Java註釋或genmodel文件以告訴生成器生成返回不可修改列表的代碼? (Google搜尋後我無法找到...)
你如何管理這種情況?
在此先感謝
馬努