有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

集合使用Java流API将列表<A>项复制到列表<B>项

我正在尝试将列表元素从List<A>复制到List<B>,并遇到一些类型错误

我的代码:

   List<AttachmentTypeDto> attachmentTypeList=clientDetails.getAttachmentTypeDto();
   List<ClientAttachmentTypeEntity> mappedAttachmentList=attachmentTypeList.stream().map(temp ->{

      ClientAttachmentTypeEntity toAttachmentObject=new ClientAttachmentTypeEntity();
      toAttachmentObject.setAttachmentTypeId(temp.getAttachmentTypeId());
      toAttachmentObject.setClientId(temp.getClientId());

  }).collect(Collectors.toList());

它给了我这样的错误:

The method map(Function<? super AttachmentTypeDto,? extends R>) in the type Stream<AttachmentTypeDto> is not applicable for the arguments ((<no type> temp) -> {})

如何解决这个错误


共 (0) 个答案