eh3rrera/ocpj8-book

Chapter 17

rcromero opened this issue · 5 comments

It's not an error but Question 7 didn't compile to me, not sure why!

The operator > is undefined for the argument type(s) Object, int

I had to cast the lambda expression to fix it
partitioningBy((Predicate<Integer>) i -> i > 5)

Also creating the predicate and using if after also worked, as I expected.
Predicate<Integer> biggerThanFive = j -> j > 5;
partitioningBy(biggerThanFive)

I tested with JDK 1.8.0_144 and it worked without casting (well, I had to change Map<Integer, Map<String, List<Integer>>> to Map<Integer, Map<Boolean, List<Integer>>>).

Then, I tested with Java 9 and it didn't compile!

I solved it by specifying the type of i explicitly, to make sure it works with both versions.

Thanks a lot! 👍

Nice! I'll check my JDK version tomorrow and do more testing on this.
I'll close this as soon I recheck.
Best Regards,
Renato

Thanks Renato!

I'm running on JDK 1.8.0_102.
I was able to compile normally the original code using javac as you already stated.
The issue might be related to my eclipse configuration.