DEV Community

Discussion on: How to convert a Java List to int []

Collapse
 
10xlearner profile image
10x learner

Hi John Mercier !

Thank you for you comment :)

I didn't know about Function.identity(), and, since I like to have the more explicit code possible, I tried it, but I obtained an error.

error: incompatible types: no instance(s) of type variable(s) T exist so that Function<T,T> conforms to ToIntFunction<? super Integer>

After some googling, I founded this stackoverflow thread and replace the i->i by Integer::intValue instead, which worked too.

Collapse
 
moaxcp profile image
John Mercier

Nice! I think identity() returns an Integer in this case and mapToInt expects an int. There is no unboxing going on here. Sorry for the confusion.