为什么EMF中的eGet返回Object而不是EObject?

I am working on some code using the EMF framework in Java, but it is really hard to use, e.g. I cannot implement OCL-like query API on top of EMF which would be type-safe.

One of the reasons is that eGet() for a EStructuralFeature returns just an Object, not EObject. So anything I would write must use much of null checking, type checking and type casting which is unsafe, not performant and cannot be generalized in a reusable way.

Why doesn't EMF generate dummy implementations with EObject wrappers for arbitrary Object value?

Implementing the EObject and hence the EClass interfaces even with simple throw UnsupportedOperationException is really a pain (the APIs are too big). The same holds for the eContainer() method which makes navigating the model upwards painful.

#0

The same method is used for accessing simple attribute values (which can be of any Java type) and traverse relationships to other modeled objects, and those can be single or multivalued.

EMF provides generic mechanisms for checking whether an object is an instance of an EClass, or if an EClass is assignable to another, so I don't really see the problem with that.

#1

The eGet() method is part of the EMF reflective API. As EMF can wrap any serializable object you cannot restrict the returned object of such a reflective API.

Why do you need to use this reflective API instead of the generated Java implementation of your ecore model? This way you will have all the direct well typed API to manipulate your domain objects.

推荐文章

主要升级-.exe文件未重新安装

主要升级-.exe文件未重新安装

推荐文章

Umbraco 5-将数据从控制器传递到视图

Umbraco 5-将数据从控制器传递到视图

推荐文章

MacOSX上的PySide和menuBar由于命名而不显示任何菜单项

MacOSX上的PySide和menuBar由于命名而不显示任何菜单项

推荐文章

解析Haskell中的特定字符串

解析Haskell中的特定字符串

推荐文章

在Pygame/Python中加载地图

在Pygame/Python中加载地图

推荐文章

需要向成员添加房屋ID

需要向成员添加房屋ID

推荐文章

如何在中打印html页net.vb版windows应用程序

如何在中打印html页net.vb版windows应用程序

推荐文章

如何在linux上从php运行imageoptim?

如何在linux上从php运行imageoptim?

推荐文章

如何用.properties文件更改ant属性位置属性

如何用.properties文件更改ant属性位置属性

推荐文章

在本地目录中获取和存储svn日志的批处理文件

在本地目录中获取和存储svn日志的批处理文件

推荐文章

单机器人JNIEnv.FindClass从图书馆

单机器人JNIEnv.FindClass从图书馆

推荐文章

替换为HTML实体的字符重新出现

替换为HTML实体的字符重新出现

推荐文章

Python不返回is目录值

Python不返回is目录值

推荐文章

VB.NET版如何检查字符串是否包含字母字符和。?

VB.NET版如何检查字符串是否包含字母字符和。?

推荐文章

Android:自定义应用程序属性,包管理器可以访问吗?

Android:自定义应用程序属性,包管理器可以访问吗?

推荐文章

等于缩略图的高度

等于缩略图的高度