Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.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
cdi实例上的javaslang List.of()_Java_Cdi_Vavr - Fatal编程技术网

cdi实例上的javaslang List.of()

cdi实例上的javaslang List.of(),java,cdi,vavr,Java,Cdi,Vavr,我创建了多个带有限定符的类: @ServiceComponent(restPath = "/trucks") public class TruckService { } @ServiceComponent(restPath = "/cars") public class CarService { } 以下是限定符(对于问题不重要) 在另一个类中,我使用javax.enterprise.inject.instance注入这些实例 class-SomeConfigurat

我创建了多个带有限定符的类:

  @ServiceComponent(restPath = "/trucks")
  public class TruckService {
  }

  @ServiceComponent(restPath = "/cars")
  public class CarService {
  }
以下是限定符(对于问题不重要)

在另一个类中,我使用javax.enterprise.inject.instance注入这些实例

class-SomeConfigurationClasss{
@注入
@ServiceComponent()
实例组件;
@凌驾
public void iterate()引发异常{
//迭代
对于(对象对象对象:_restComponents){
somefunction(obj);
}
//(_rest组件)列表
//.flatMap(obj->somefunction(obj));
}
}
如果我执行“正常”迭代(for…),我会得到作为somefunction()参数给定的对象(TruckService或CarService)

但是如果我使用List.of(…),我会得到实例本身。我认为这是预期的行为

是否可以在可以包含一个或多个bean的实例上使用List.of(取决于注入绑定)。(我已经尝试在实例上调用迭代器(),select())

实例扩展了Iterable
,因此您应该使用

    @Qualifier
    @Retention(RetentionPolicy.RUNTIME)
    @Target({TYPE, FIELD})
    public @interface ServiceComponent {

        public boolean exposeAsRest() default true;

        @Nonbinding public String restPath() default "";

        @Nonbinding public String restGetPrefix() default "get,find,all";

        @Nonbinding public String restPostPrefix() default "create,new,post";
    }
    class SomeConfigurationClasss {

        @Inject
        @ServiceComponent()
        Instance<Object> _restComponents;

         @Override
          public void iterate() throws Exception {

              //iterate
              for(Object obj : _restComponents){
                  somefuncion(obj);

              }

              //List.of(_restComponents)
                //.flatMap(obj -> somefuncion(obj));

          }

      }