import com.google.common.collect.Lists;
import lombok.Data;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public class Test {
public static void main(String[] args) {
TaskNode taskNode = new TaskNode();
ArrayList<TaskNode> taskNodeList = Lists.newArrayList(taskNode);
List<String> nodeStateList2 = taskNodeList.stream()
.map(taskNode1 -> getString(taskNode1.getConfig(), ""))
.collect(Collectors.toList());
}
public static <K> String getString(final Map<? super K, ?> map, final K key) {
if (map != null) {
final Object answer = map.get(key);
if (answer != null) {
return answer.toString();
}
}
return null;
}
}
@Data
class TaskNode{
private LinkedHashMap config;
}
Unable to compile and On the console display: “java.lang.Object Unable to convert to
java.util.List<java.lang.String>”
I know it’s because the TaskNode.config property doesn’t declare generics, but I don’t understand why. Can you explain in detail the reasons for the occurrence
New contributor
王荣杰 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.