Reputation: 9763
Can someone tell me what I am doing wrong here? p.getVote()
, and the collection counting logic return a Long, but I am trying to make my end output an array of ints.
Map<Integer, Long> counters = iqr.getQgagueUniqueVotes().stream()
.collect(Collectors.groupingBy(p -> ((int)p.getVote()),
Collectors.counting()));
Collection<Long> values = counters.values();
long[] targetArray = values.toArray(new Long[values.size()]);
Error:
Incompatible type: Inference variable has incompatible upper bound
Upvotes: 2
Views: 73
Reputation: 56453
Change the type of the targetArray
array to a type Long
:
Long[] targetArray = values.toArray(new Long[values.size()]);
or create a stream of the values and map to a type long
then collect to an array.
long[] targetArray = values.stream().mapToLong(Long::longValue).toArray();
Upvotes: 3