This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!

claude lepere

Greenhorn
+ Follow
since Oct 01, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by claude lepere

Good evening, Jeanne.

ISBN: 978-1-119-06790-0
ISBN: 978-1-119-06788-7 (ebk.)
ISBN: 978-1-119-06789-4 (ebk.)

p. 432 in the middle of the page: [Animal [name=null, age=0, type=P], Animal [name=null, age=0, type=P]]

This is the output I get if "this.type = 'Q';" is present in the constructor "Animal()" and if "this.type = type;" is also present in the constructor "Animal(String name, int age, char type)"
but, char type is static in the class "Animal", both statements strictly speaking should not be present in the constructors.
If I comment out both statements, "type=P" in the output is now "type=C", which is correct because as the static field "type" is not serialized, the value of "type" is not present in the returned object from the deserialization but comes from a new instanciation of the class.

My question is: since the field "type" is not serialized, where does the value 'P' come from then?

Please, excuse my low level of English.

Thanks in advance for your answer. Claude Lepère
2 weeks ago
Hello.

In
OCP Oracle Certified Professional Java SE 8 Programmer II STUDY GUIDE
EXAM 1Z0-809
Jeanne Boyarsky and Scott Selikoff
SYBEX A Wiley Brand
Copyright 2016
ISBN: 978-1-119-06790-0

p. 223: example of mapping collector adding a lower level collector:
As said in errata, does not compile with some versions of Java 8:

error: no suitable method found for groupingBy(String::length,Collector<Object,CAP#1,Optional<T#1>>)
       Map<Integer, Optional<Character>> map = ohMy.collect(Collectors.groupingBy(
                                                                      ^
   method Collectors.<T#3,K#1>groupingBy(Function<? super T#3,? extends K#1>) is not applicable
     (cannot infer type-variable(s) T#3,K#1
       (actual and formal argument lists differ in length))
   method Collectors.<T#4,K#2,A#1,D#1>groupingBy(Function<? super T#4,? extends K#2>,Collector<? super T#4,A#1,D#1>) is not applicable
     (inferred type does not conform to upper bound(s)
       inferred: Object
       upper bound(s): T#5,Comparable<? super T#5>,Object)
   method Collectors.<T#6,K#3,D#2,A#2,M>groupingBy(Function<? super T#6,? extends K#3>,Supplier<M>,Collector<? super T#6,A#2,D#2>) is not applicable
     (cannot infer type-variable(s) T#6,K#3,D#2,A#2,M
       (actual and formal argument lists differ in length))
 where T#1,T#2,T#3,K#1,T#4,K#2,A#1,D#1,T#5,T#6,K#3,D#2,A#2,M are type-variables:
   T#1 extends T#2
   T#2 extends Comparable<? super T#2>
   T#3 extends Object declared in method <T#3,K#1>groupingBy(Function<? super T#3,? extends K#1>)
   K#1 extends Object declared in method <T#3,K#1>groupingBy(Function<? super T#3,? extends K#1>)
   T#4 extends Object declared in method <T#4,K#2,A#1,D#1>groupingBy(Function<? super T#4,? extends K#2>,Collector<? super T#4,A#1,D#1>)
   K#2 extends Object declared in method <T#4,K#2,A#1,D#1>groupingBy(Function<? super T#4,? extends K#2>,Collector<? super T#4,A#1,D#1>)
   A#1 extends Object declared in method <T#4,K#2,A#1,D#1>groupingBy(Function<? super T#4,? extends K#2>,Collector<? super T#4,A#1,D#1>)
   D#1 extends Object declared in method <T#4,K#2,A#1,D#1>groupingBy(Function<? super T#4,? extends K#2>,Collector<? super T#4,A#1,D#1>)
   T#5 extends Comparable<? super T#5> declared in method <T#5>naturalOrder()
   T#6 extends Object declared in method <T#6,K#3,D#2,A#2,M>groupingBy(Function<? super T#6,? extends K#3>,Supplier<M>,Collector<? super T#6,A#2,D#2>)
   K#3 extends Object declared in method <T#6,K#3,D#2,A#2,M>groupingBy(Function<? super T#6,? extends K#3>,Supplier<M>,Collector<? super T#6,A#2,D#2>)
   D#2 extends Object declared in method <T#6,K#3,D#2,A#2,M>groupingBy(Function<? super T#6,? extends K#3>,Supplier<M>,Collector<? super T#6,A#2,D#2>)
   A#2 extends Object declared in method <T#6,K#3,D#2,A#2,M>groupingBy(Function<? super T#6,? extends K#3>,Supplier<M>,Collector<? super T#6,A#2,D#2>)
   M extends Map<K#3,D#2> declared in method <T#6,K#3,D#2,A#2,M>groupingBy(Function<? super T#6,? extends K#3>,Supplier<M>,Collector<? super T#6,A#2,D#2>)
 where CAP#1 is a fresh type-variable:
   CAP#1 extends Object from capture of ?
com\ictjob\clep\MyMain.java:168: error: cannot find symbol
                   Collectors.mapping(s -> s.charAt(0), Collectors.minBy(Comparator.naturalOrder()))));
                                            ^
 symbol:   method charAt(int)
 location: variable s of type Object
com\ictjob\clep\MyMain.java:167: error: invalid method reference
                   String::length,
                   ^
 non-static method length() cannot be referenced from a static context
3 errors

========

I am working with the following version:
javac -version
javac 1.8.0_121

Here, with help of https://stackoverflow.com/questions/24565278/java-util-comparator-naturalorder-takes-a-t-extends-comparable-super-t-and, 2 codes that compile and run:





The problem is that the missing type variable "Character" but I do not clearly understand the syntax in the second code "Comparator.<Character>naturalOrder(). Could you please explain? Thank you.

11 months ago
Jeanne,

In
OCP Oracle Certified Professional Java SE 8 Programmer II STUDY GUIDE
EXAM 1Z0-809
Jeanne Boyarsky and Scott Selikoff
SYBEX A Wiley Brand
Copyright 2016
ISBN: 978-1-119-06790-0

p. 143, Comparator vs. Comparable, paragraph after the NOTE:
"There is also a class called Comparator,"
As Comparator is a functional interface, I think replacing "class" with "interface" should be clearer, but I agree with your previous answer that an interface is a type of class.
Jeanne,

Very fast answer! Sorry for not being specific: I am studying with this - very good - book:
OCP Oracle Certified Professional Java SE 8 Programmer II STUDY GUIDE
EXAM 1Z0-809
Jeanne Boyarsky and Scott Selikoff
SYBEX A Wiley Brand
Copyright 2016
ISBN: 978-1-119-06790-0

and the supposed typo is in Chapter 2 - Design Patterns and Principles,
Defining a Functional Interface,
p. 54,
second line of the second to last paragraph
p54, in the second last paragraph, I think that in "The Walk interface neither extends any functional interface classes nor ..." the word "classes" should be removed.