Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用类型为<;的ContextInjectionFactory;T>;_Java_Dependency Injection_Rcp - Fatal编程技术网

Java 使用类型为<;的ContextInjectionFactory;T>;

Java 使用类型为<;的ContextInjectionFactory;T>;,java,dependency-injection,rcp,Java,Dependency Injection,Rcp,使用DependencyInjection/ContextInjectionFactory而不生成类型安全警告的正确方法是什么 public class MyClass<T> {...} // Without Dependency Injection MyClass<MyType> x = new MyClass<MyType>(); // With Dependency Injection and TypeSafety warning MyCl

使用DependencyInjection/ContextInjectionFactory而不生成类型安全警告的正确方法是什么

 public class MyClass<T> {...}

 // Without Dependency Injection
 MyClass<MyType> x = new MyClass<MyType>();

 // With Dependency Injection and TypeSafety warning
 MyClass<MyType> x = ContextInjectionFactory.make(MyClass.class, context);
公共类MyClass{…}
//没有依赖注入
MyClass x=新的MyClass();
//带有依赖注入和类型安全警告
MyClass x=ContextInjectionFactory.make(MyClass.class,上下文);

您可以使用通配符来避免生成类型安全警告:-

MyClass<?> x = ContextInjectionFactory.make(MyClass.class, context);
MyClass x=ContextInjectionFactory.make(MyClass.class,context);

您必须使用通配符generic

MyClass<?> x = ContextInjectionFactory.make(MyClass.class, context);
MyClass<MyType> myClass = (MyClass<MyType>) x;