我想迭代一个对象列表。每个对象都包含一些对象变量。更具体地说:
public class KCenterDocumentMapping {
private DigitalFileCategory digitalFileCategory;
private DocumentType documentType;
private KCenterCategory kCenterCategory;
private KCenterFolder kCenterFolder;
private KCenterDocumentType kCenterDocumentType;
//setters & getters
}
我的清单是:
List<KCenterDocumentMapping> allMappings = db4.retrieveMapping();
所需的地图结构是:
Map<DigitalFileCategory, Map<DocumentType, KCenterDocumentMapping>> kCenterDocumentMappingMap = new HashMap<>();
在我当前的实现中,我收到“无法从静态上下文引用非静态方法”。
Map<DigitalFileCategory, Map<DocumentType,KCenterDocumentMapping>> grouping = kCenterDocumentMappingList.stream()
.collect(Collectors.groupingBy(KCenterDocumentMapping::getDigitalFileCategory,
Collectors.mapping(KCenterDocumentMapping::getDocumentType, this)));
有什么想法吗?
答案 0 :(得分:2)
Collectors.mapping(KCenterDocumentMapping::getDocumentType, this) // this?
我认为你正在寻找的是:
Collectors.toMap(KCenterDocumentMapping::getDocumentType,
Function.identity())
Collectors.mapping
接受Function
和Collector
作为输入; this
看起来不像Collector