将 java.net.URI 转换为 org.eclipse.emf.common.util.URI
Java 中至少有两种类型的 URI:
java.net.URI
org.eclipse.emf.common.util.URI
我有 java.net。 URI
并且需要使用EMF URI。如何将前者转换为后者?
如果我尝试 new URI uri = profileUrl.toURI()
我会收到这样的消息:
Type mismatch: cannot convert from java.net.URI to org.eclipse.emf.common.util.URI
我还尝试了某种解决方法,它将从 java.net.URI< 创建一个字符串/code> 并使用新字符串和新 EMF URI...这会导致文件未找到异常。
There are at least two types of URIs in Java:
java.net.URI
org.eclipse.emf.common.util.URI
I have java.net.URI
and need to use the EMF URI. How can I convert the former to the latter?
If I try new URI uri = profileUrl.toURI()
I will get a message like this:
Type mismatch: cannot convert from java.net.URI to org.eclipse.emf.common.util.URI
I tried also some kind of workaround that will create a string from the java.net.URI
and with the new string a new EMF URI... this lead to a file-not-found exception.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,“Java 中不存在两种类型的 URI”:Java 中只有一种,EMF 中只有一种,EMF 是为建模而构建的框架。他们有自己的 URI 实现,因为这反映了他们自己的概念之一,或者他们需要的超出了 Java 的 URI 允许的范围,或者......这样的选择可能有多种原因,并且许多框架提供了自己的此类版本或此类(在 Eclipse 中,使用 ctrl + shift + T 并输入“List”或“Array”作为示例)。
至于实际问题,没有办法直接从
java.net.URI
到org.eclipse.emf.common.util.URI
:你需要将 Java URI 转换为字符串,然后围绕该字符串创建一个新的 URI。像这样的事情:您需要使用两个 URI 中至少之一的完全限定名称:您没有在 Java 类中导入的一个。从你的问题来看,我想说你已经导入了 org.eclipse.emf.common.util.URI,因此可以简单地使用它:
First things first, there are not "two types of URIs in Java": there is only one in Java, and one in EMF which is a framework built for modeling. They have their own implementation of URI because this reflects one of their own concepts, or they needed more than Java's URI allows, or... there can be a number of reasons for such a choice, and many frameworks provide their own version of such or such class (in Eclipse, use ctrl + shift + T and type "List" or "Array" for examples).
As for the actual question, there is no way to go directly from a
java.net.URI
toorg.eclipse.emf.common.util.URI
: you need to convert the Java URI to a string, then create a new URI around this string. Something like this:You need to use the fully qualified name of at least one of the two URIs: the one you did not import in your Java class. Judging by your question, I'd say you have imported
org.eclipse.emf.common.util.URI
, and thus can simply use this: