A software developer. I'm interested in learning new technologies and core language features. I love to dive into legacy code writing tests and refactoring as I go.
One thing I found useful in cases like this is to use Function.identity(). This can replace i ->i in the call to mapToInt. I prefer this because I think it is more obvious what is being done in the stream.
A software developer. I'm interested in learning new technologies and core language features. I love to dive into legacy code writing tests and refactoring as I go.
One thing I found useful in cases like this is to use
Function.identity()
. This can replacei ->i
in the call tomapToInt
. I prefer this because I think it is more obvious what is being done in the stream.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.After some googling, I founded this stackoverflow thread and replace the
i->i
byInteger::intValue
instead, which worked too.Nice! I think
identity()
returns an Integer in this case andmapToInt
expects anint
. There is no unboxing going on here. Sorry for the confusion.