Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.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 guice、MapBinder和参数化接口_Java_Guice - Fatal编程技术网

Java guice、MapBinder和参数化接口

Java guice、MapBinder和参数化接口,java,guice,Java,Guice,我正在使用guice和MapBinder。我有以下服务接口: public interface IService<K, V> 公共接口iSeries设备 和两个实现: public class AService implements IService<String, String> public class BService implements BService<String, String> public类服务实现IService 公共类BServi

我正在使用guice和MapBinder。我有以下服务接口:

public interface IService<K, V>
公共接口iSeries设备
和两个实现:

public class AService implements IService<String, String>
public class BService implements BService<String, String>
public类服务实现IService
公共类BService实现BService
我想像这样使用MapBinder:

MapBinder<String, IService<String, String>> mapBinder =
            MapBinder.newMapBinder(binder(), String.class, WHAT_TO_DO_HERE);
MapBinder MapBinder=
newMapBinder(binder(),String.class,此处的任务);
因为我做不到

IService<String, String>.class 
IService.class
在这里的WHAT_TO_DO_部分中,我的第一个想法是为iSeries设备创建一个标记接口,然后继续。我的问题是:

  • 在guice中执行此操作的最佳实践是什么

  • 标记接口的想法在这里有问题吗?若然,原因为何


  • 谢谢

    您可以尝试一种
    TypeLiteral

    WHAT_TO_DO_HERE=new TypeLiteral(){};
    
    比如说,Javadoc有一个合适的
    newMapBinder
    方法,尽管您还必须将
    String
    类包装到
    TypeLiteral

    WHAT_TO_DO_HERE = new TypeLiteral<IService<String, String>>(){};