我有一个我不能解决的问题。我正在学习equinox变换,但我不能解决这个问题,我在我的Activator中放了这段代码:
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中的示例代码:
Dictionary properties = new Hashtable();
properties.put("equinox.transformerType", "xslt");
registration = context.registerService(URL.class.getName(), context.getBundle().getEntry("/transform.csv"), properties);是对的吗?
发布于 2014-09-08 16:27:26
您从Eclipse得到的编译错误是BundleContext类型中的registerService(String,Object,Dictionary)不适用于参数(String,URL,Properties),这是正确的。这是因为java中的泛型。java.util.Properties类扩展了哈希表,哈希表遵循通用规则。现在,如果您看到BundleContext.reregisterService()期望的参数
ServiceRegistration<?> registerService(String clazz, Object service, Dictionary<String, ?> properties);很清楚地提到,它期望第三个参数为Dictionary<.String,?>。
因此,当您使用简单属性时,它无法在编译时识别这第三个参数的类型。
所以,你的第二种方法是正确的:
Dictionary properties = new Hashtable();
properties.put("equinox.transformerType", "xslt");
registration = context.registerService(URL.class.getName(),
context.getBundle().getEntry("/transform.csv"), properties);您甚至可以通过将字典引用更改为
Dictionary<Object,Object> properties = new Hashtable();它会再次给你同样的编译时错误。
您可以获得有关泛型here的更多信息。
你可以在Equinox Transform revealed上阅读更多关于Equinox变换和示例的内容。
发布于 2012-01-24 22:51:23
当您使用Properties对象时,import语句是什么?看起来您可能没有使用java.util.Properties (java.util.Dictionary的子类)。有相当多的类被称为属性。
https://stackoverflow.com/questions/8988034
复制相似问题