Biniman Idugboe

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

Recent posts by Biniman Idugboe

I get it now.  Thanks to everyone.
2 months ago
By the way, what does it mean to "Grant up to 2 flag(s)" ?
What is the meaning of flagging a thread for attention?
2 months ago
Thanks a lot Mr. Campbell.  At least now, I have some idea of what's going on behind the scene of the Stream interface.
2 months ago
Thanks for the correction, Mr. Campbell.
2 months ago

I have no idea about what to say, regarding the JShell output.
The reason I sought to know the class that implemented the Stream interface?  Well, Arrays.asList() returns an instance of ArrayList. I know that ArrayList implemented List.  So, I know that I can assign the instance of ArrayList to a variable of type List and maybe to a variable of type Collection.  I thought, perhaps needlessly, that if I have an idea of the class whose instance is returned by the stream() method, I might have a fuller idea of what to do with the stream returned.
2 months ago

Stream.of(new Result())



Example:
2 months ago
I have something like the following:

Now, dataStream is an instance of type Stream.  But Stream is an interface and its instance has to be derived from a class that has already implemented the Stream interface.  My question is which class has provided implementations for all the abstract methods of the Stream interface?
2 months ago
Thank you Sir.  Your explanations have largely peeled off the layer of mystery.  I am trying to remember who said it wasn't difficult to learn Java language.
2 months ago
So, the groupingBy(Person::getCity) chooses to return an instance of a class that has already implemented the Map interface.  On what basis does the groupingBy() make this decision?
I am thinking that at this moment, the groupingBy() has no way to know what methods I will invoke on the object it returned.  Yet it chooses a specific type for me? And the type is actually what I need. I am thinking of a mind reader!
 
2 months ago
So, I have the following code snippet. It compiles and runs without error.

I thought abstract methods have to be implemented before they can be used. Here, I see three abstract methods namely entrySet(), getkey() and getValue().  I do not see any implementing codes for them and yet the for loop works as expected.  What is going on?  Are there abstract methods that do not need implementations, that is, do they have hidden implementations?
2 months ago
By the way, can I mark my own post as helpful?
2 months ago

In fact a simple sequential stream might only need enough memory for one element. Once that element has been finished with, the memory location is filled by the reference to the next element. There is often no need to keep a record of how many elements have been processed.


That clarifies it all for me.  Thanks.
2 months ago
Thanks Marc and Stephan.  A new stream has to be created in order to repeat the same operation, then whatever happened to reusability.  Isn't reusabelility supposed to be an important aspect of Java programming?
2 months ago


(1) isEqual(Object targetRef)
The parameter declaration says thay you can pass the instance of any class to this method. All the classes in Java are subclasses of the Object class.

(2) <T> Predicate<T>
The T is a place holder for a specific type.  Normally, if you want to create a list designed to hold only instances of Dog, you would write List<Dog>.  However, in the context of isEqual() method, you have not way to know the class of the instance that will be passed to the method.  That means you have no way to know the class of instances that the predicate will be testing. Even so, the class can be inferred from the argument passed to the method. Therefore, the <T> before the Predicate<T> is Java's way of saying "the T will be replaced with the class of the argument passed to the method".
Now, if you do the floowing:

Java will work out the fact the dog was created from Dog.  Therefore, the isEqual() method will return type Predicate<Dog>. The T has been replaced with Dog. If you now try to use this predicate to test instances of Cat, the compiler will shoot out an error because a Cat class is not a Dog class.
2 months ago