Paul Anilprem

Enthuware Software Support
+ Follow
since Sep 23, 2000
Merit badge: grant badges
Cows and Likes
Cows
Total received
52
In last 30 days
0
Total given
3
Likes
Total received
610
Received in last 30 days
4
Total given
177
Given in last 30 days
1
Forums and Threads

Recent posts by Paul Anilprem

Stephan van Hulst wrote:

Paul Anilprem wrote:But even a static method can't be marked final in an interface! One can only guess why.


What would it even mean for a static interface method to be final? Static interface methods aren't inherited in the first place.



It would mean the same that it does for a class. That it can't be hidden!
While a class implementing an interface may have to redefine a default method if it inherits the same from two interfaces, there is no such issue with a static method. But even a static method can't be marked final in an interface! One can only guess why.

You can definitely use an IDE if that helps you get started quickly if you are beginner. Using an IDE does feel more exciting than using the command line.
But if you decide to prepare for any Java certification, it is advisable to spend a good amount of time in learning how to do things from the command line for reasons explained here.
5 days ago

Mike Simmons wrote:
With this method, how would you ever get a V instance at all?  You have a stream of T, and you have a BiFunction to take a V and a T, and return a V.  Which means you need at least one V to use that function.  That's why you need an identity V instance, to start the reduction off.  


Right. I missed that.

Mike Simmons wrote:
And for parallel processing, each worker thread will use that same identity V instance to start off processing its own subset of elements, before combining later with the combiner.  And if any of those worker threads finds there are no elements for them to process (maybe it turns out that there's a filter() method that eliminates all the elements that might have been expected) you want the worker to not freak out and throw an exception, just return the identity value unmolested, so it can still be combined with the other results safely.


Right again.
thank you!
1 week ago

Campbell Ritchie wrote:
Another reason, maybe, for not throwing exceptions from an empty Stream is that exceptions are supposed to respond to something abnormal, and an empty Stream is regarded as a normal occurrence.


Yes, I agree with that. It seems reasonable.

What I am not sure about now is the reason behind having the following three methods in the Stream interface (i.e. the regular Stream interface and not the primitive stream interfaces such as IntStream) :
  • Optional<T> reduce(BinaryOperator<T> accumulator)
  • T reduce(T identity, BinaryOperator<T> accumulator)
  • V reduce(V identity, BiFunction< V,? super T,V> accumulator, BinaryOperator<V> combiner)


  • but not having:

    Optional<V> reduce(BiFunction<V,? super T, V> accumulator, BinaryOperator combiner)

    1 week ago

    Paul Anilprem wrote:

    Campbell Ritchie wrote:Isn't that what happens if you use the method without the identity parameter?


    No, the one that doesn't take identity parameter takes one parameter of type BinaryOperator. A BinaryOperator restricts you to returning the same type as the type of the stream.
    In fact, now I wonder why did they not design this method to accept a BiFunction like the other reduce method.



    Because that would require a combiner, of course!
    1 week ago

    Campbell Ritchie wrote:Isn't that what happens if you use the method without the identity parameter?


    No, the one that doesn't take identity parameter takes one parameter of type BinaryOperator. A BinaryOperator restricts you to returning the same type as the type of the stream.
    In fact, now I wonder why did they not design this method to accept a BiFunction like the other reduce method.
    1 week ago

    Campbell Ritchie wrote:
    The reason for not throwing an exception is that the designers didn't want Streams to fail to complete their runs.


    Right. I should rephrase it as:
    "So, it is not entirely implausible to think that multiplying the elements of an empty set of Integers should be undefined, in which case an RTE is more appropriate returning an empty Optional is more appropriate. "

    What I am trying to get at is that returning Identity makes the method more rigid than what is warranted. It doesn't allow the the programmer to have an alternate path if there are no elements in the stream.  Given that there already are a buttload of methods, what's one more? Unless it is doesn't make sense logically.
    1 week ago
    No, that is not possible because Oracle has discontinued 1z0-815 and 1Z0-816 exams. Now, there is just one exam for OCP Java 11 and that is 1Z0-819. Similarly, there is just one exam for OCP Java 17 and that is 1Z0-829.

    Paul Clapham wrote:And since the empty set is a set, the product of the empty set of integers has an integer value too.



    Stephan van Hulst wrote:Man, I would be so upset if multiplying zero integers would return anything other than 1. Throwing an exception is what I would call "an insidious bug".



    I was watching a video on Russel's paradox on youtube (https://www.youtube.com/watch?v=ymGt7I4Yn3k&t=698s) and at around 11.50, while explaining empty sets, he says that there is exactly one empty set and that two empty sets are really the same set.

    If he is right, an empty set is as much a set of Integers as it is a set of monkeys. So, it is not entirely implausible to think that multiplying the elements of an empty set of Integers should be undefined, in which case an RTE is more appropriate.

    Not really questioning the logic behind the reduce(U identity,  BiFunction<U,? super T,U> accumulator, BinaryOperator< U> combiner) because returning identity for an empty set is also valid from one perspective, but since they already have so many methods, they could have easily had one that didn't take an identity parameter and threw an RTE for empty stream as well i.e., reduce( BiFunction<U,? super T,U> accumulator, BinaryOperator< U> combiner).

    (Fixed formatting)
    1 week ago

    Naizak Aram wrote:
    for example in this question there are 6 myFavoriteNumbers variables. do I have to check for spelling errors in each of them?
    regards,


    No, the exam questions do not try to trick you on that point. While you may see spelling mistake in  question the answer will not depend on that. In your example, you may see myFavoriteNumbers mistyped as myFavoriteNmbers but you can ignore that as a typo. If the correct answer is Compilation error, it would be because of something else.
    @Anil, Just wanted to confirm if this explanation was displayed or not when you viewed the solution. If it was then I will take it as the explanation wasn't enough and will mark it as requiring improvement.

    Mike Simmons wrote:But I believe it refers to the fact that a class or interface can define multiple nested types, in addition to defining a type for itself.


    Yes, that makes more sense.

    Stephan van Hulst wrote:A type can not be a subset of another type because types are not sets.


    Oh but they are. That is how the JLS defines them. See section 4.5: A class or interface that is generic (§8.1.2, §9.1.2) defines a set of parameterized types.