The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Campbell Ritchie (101) [Avatar] Offline
The λ on page 41 shows a1.getWeight().compareTo.(a2.getWeight())
This will of course not compile because you can't call methods on an int. In that instance, ints are not boxed to Integers. It should read
(a1.getWeight() > a2.getWeight() ? 1 : a1.getWeight() < a2.getWeight() ? -1 : 0)
but if the weights are small positive ints, you can get away with
a1.getWeight() - a2.getWeight()
without risk of overflow errors.

Message was edited by:
Minor spelling errors.
undjask (13) [Avatar] Offline
Re: Boxing or not boxing on page 41
The code on page 41 compiles and runs just fine, because getWeight returns an Integer. If you are going to change getWeight into returning a primitive int you probably want to use,a2.getWeight()), which works since Java 7.

I hope, someday Oracle will get rid of primitive values and walks down the same path like Scala or C++ providing suitable value types, so nobody has to use primitives again, ever...