Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!

Biniman Idugboe

Ranch Hand
+ Follow
since Jun 09, 2017
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Biniman Idugboe

Thanks.  My primary intention was to be able to assemble the correct arguments to pass to the comparing method. With the help of you and others, that intention has been largely achieved.
13 hours ago
Got is now.  I replaced all occurrences of int with Integer and created a Comparator<Integer>.

Comparator<Integer> comparator = (Integer n1, Integer n2) -> n1.compareTo(n2);

Took me inordinate time to figure out.
Thanks to everybody who participated in one way or the other.
17 hours ago
Correction to one of the methods in Person class.

I wasn't even able to edit my post.
1 day ago
Unfortunately, I still do not know how to resolve the problem.  I am also assuming that the overloaded version of the comparing method is the only version available.  How can I use this version to sort a list of persons by their weight?  If I knew the answer, I most likely won't bring up the question on this forum.
1 day ago
The following was copied from Java 1.8 documentation.

static <T, U> Comparator<T> comparing(Function<? super T, ? extends U> keyExtractor, Comparator<? super U> keyComparator)
Accepts a function that extracts a sort key from a type T, and returns a Comparator<T> that compares by that sort key using the specified Comparator.

So, I tried to sort a list of persons based on their weight. My code is shown below.  The problem is that I am not able to correctly specify the the argument to pass to the second parameter of the comparing method (See line 26 and line 27 of my code).  Please, educate me.

1 day ago
Thanks everybody.  Very useful suggestions and recommendations.  Resolved!
2 weeks ago
Thanks for the cow and for the analysis.  Here's my understanding of your explanations:
An inner class must be declared static if there is a possibility that the inner class will be referenced from a static context.
Question: Is it not better to declare all inner classes static?

An interface that is nested inside a class, is implicitly static; otherwise the interface will not be accessible outside the enclosing class. 
Question:  If we can have implicitly static interface, why can't we have explicitly static interface?
2 weeks ago
Hello All,
Please, look at the newbie program below:

When compiled, I get the following error:

..\rawcodes\ error: non-static variable this cannot be referenced from a static context
                Arranger inOrder = new Arranger();

The inner class and the interface are both at the same level of visibility.  Why am I able to implement the interface in the static context and yet not able to instantiate the inner class? What does the static context think of the inner class?

2 weeks ago
Again, thank you. Resolved!
3 weeks ago
Yes, I did.  I have just recompiled and ran the program again.  The result is the same - outer.
3 weeks ago
What a relief!  I cannot thank you enough. So many nuances in Java.
3 weeks ago
The following code was adapted from SCJP (Exam 310-065) by Kathy Sierra and Bert Bates, page 697, Question 8.

The result is:

>java TestInners

I was waiting to receive a runtime error. It appears the compiler decided to replace new A().m() with new D().m().  How did it arrive at that kind of decision?
3 weeks ago
Here's the complete code.
3 weeks ago
Thanks for your responses.  As I said previously, the code compiles and runs when I use:

Instead of:

And I am asking to know what the W extends T is saying to the method.

<T>  is replaced with <Dog>
<V> is replaced with <Cat>
<W> is replaced with <Poodle> and Poodle is a legal subclass of Dog. So, what is the compiler complaining about?
3 weeks ago
Thanks Mr. Campbell.  I have edited the code as shown below.  The compiler is still unhappy.

error: > expected
        public <T, V> V fetchInstance(List<T> tList, List<V> vList, List<W extends T> wList)

Here is a similar program that compiles and runs without error. 

What is exactly the difference between the extends keyword  in the copy() method and the extends keyword in the  getInstance() method?
3 weeks ago