Hervé Lionel Ondoua

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

Recent posts by Hervé Lionel Ondoua

Nt c1 but c2. It is from a book
3 years ago
COnsidering the code below:



It is said that this code does not compile because of line q2 since c2 is an integer.
Can someone help me to figure out how c2 can be an integer?
3 years ago

Stephan van Hulst wrote:When you pass a lambda or a method handle to a method, the compiler only cares that the type of the lambda or method handle is compatible with the functional interface that the method accepts.

SortTest and MySorter may not implement Comparator, but Comparator is a functional interface of type ((Person, Person) -> int). That means you can pass any method handle as a Comparator, as long as the method is of type ((Person, Person) -> int).

Both SortTest::diff and anInstanceOfMySorter::compare have this type.



Thank you
3 years ago
Could you help me please to clearly understand why the code below does not compiles?


Thank you in advance.

[edited to fix code tag]
3 years ago
Given:  


and the following lines of code:
I     java.util.Collections.sort(al, (p1, p2)->p1.dob.compareTo(p2.dob));          
II    java.util.Collections.sort(al, SortTest::diff);  
III   java.util.Collections.sort(al, new MySorter()::compare);          
IV    java.util.Arrays.sort(al, SortTest::diff);  

How many of the above lines can be inserted into the given code, independent of each other, to sort the list referred to by al?

This is a question I took in a simulator for OCP.
For me the answer is one (1): ine I, since the SortTest and MySorter do not implement Comparator and line IV is for arrays.

But the answer is lines I, II and III. I would like you to help me figure out why is it the case please.

Thank you.
3 years ago
Thank you Jesper de Jong.

Thus no matter if the mapping Bifunction returns null or not, since the value is null the computeIfpresent() does not change anything on the map, is that right?
3 years ago
I am reading the nice  book of Jeanne Boyarsky and Scott Selikoff (The study Guide for OCP).
But I have an issue with this:

Let suppoze that this is the contain of a map m: [jenny=null]
If we apply m.computeIfPresent("jenny", (k,v) -> null), from what I understand the pair key/value is going to be deleted.

I am right? because the recap in page 159 is the contrary.

I would like to be fixed please.
3 years ago
Thank you. This is what clearly what I understand.

But from the last sentence, this is what I understand and it does work:

given,
public class OuterClass{
private str= "From Outer"

protected class InnerClass{
}
}

public class Main extends Outer.InnerClass{
}
Hello everyone,
On my way to get OCPJP 8, I started the preparation. My problem is about the following sentence:
"A nested class has access to all the private members of its enclosing class—both fields and methods. Therefore, a public or protected nested class inherited by a subclass has indirect access to all of the private members of the superclass."

I read it here: https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html

Please, help me to clearly understand it.