首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Equinox转换激活器

Equinox转换激活器
EN

Stack Overflow用户
提问于 2012-01-24 21:57:16
回答 2查看 341关注 0票数 0

我有一个我不能解决的问题。我正在学习equinox变换,但我不能解决这个问题,我在我的Activator中放了这段代码:

代码语言:javascript
复制
Properties properties = new Properties();
properties.put("equinox.transformerType", "xslt"); //$NON-NLS-1$ //$NON-NLS-2$
registration = context.registerService(URL.class.getName(), context.getBundle().getEntry("/transform.csv"), properties); //$NON-NLS-1$

但是Eclipse告诉我registerService方法不能与这些参数(String、Url、Properties)一起使用,它只接受(String、Url、Dictionary)。Equinox_Transforms中的示例使用的方法与我使用的方法相同,但在这些情况下它是有效的。

有什么问题吗?

我用下面的代码修改了我的Activator中的示例代码:

代码语言:javascript
复制
Dictionary properties = new Hashtable();
properties.put("equinox.transformerType", "xslt");
registration = context.registerService(URL.class.getName(), context.getBundle().getEntry("/transform.csv"), properties);

是对的吗?

EN

回答 2

Stack Overflow用户

发布于 2014-09-08 16:27:26

您从Eclipse得到的编译错误是BundleContext类型中的registerService(String,Object,Dictionary)不适用于参数(String,URL,Properties),这是正确的。这是因为java中的泛型。java.util.Properties类扩展了哈希表,哈希表遵循通用规则。现在,如果您看到BundleContext.reregisterService()期望的参数

代码语言:javascript
复制
ServiceRegistration<?> registerService(String clazz, Object service, Dictionary<String, ?> properties);

很清楚地提到,它期望第三个参数为Dictionary<.String,?>。

因此,当您使用简单属性时,它无法在编译时识别这第三个参数的类型。

所以,你的第二种方法是正确的:

代码语言:javascript
复制
Dictionary properties = new Hashtable();
properties.put("equinox.transformerType", "xslt");
registration = context.registerService(URL.class.getName(),     
context.getBundle().getEntry("/transform.csv"), properties);

您甚至可以通过将字典引用更改为

代码语言:javascript
复制
Dictionary<Object,Object> properties = new Hashtable();

它会再次给你同样的编译时错误。

您可以获得有关泛型here的更多信息。

你可以在Equinox Transform revealed上阅读更多关于Equinox变换和示例的内容。

票数 2
EN

Stack Overflow用户

发布于 2012-01-24 22:51:23

当您使用Properties对象时,import语句是什么?看起来您可能没有使用java.util.Properties (java.util.Dictionary的子类)。有相当多的类被称为属性。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8988034

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档