Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Spring in Action (5th edition) this week in the Spring forum!

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
5
Received in last 30 days
0
Total given
72
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 am not suggesting that anybody is laughing at me.  Recall that earlier in this thread, I asked that nobody should laugh as a result of what I was about to say.  You know, there are somethings that can make you laugh even if you didn't want to laugh.  Some things could be so ridiculous or perhaps, so funny that they are laughable.  Yeah!  I am trying to get understanding, so I will not be offended if my statements provoke laughter.
Now, the reason I used

is because one of the lower bounds reported by the error message is java.lang.Object.  I just wanted to be sure that when the right hand side of the statement is cast to Object, the statement will execute without error.
1 month ago
My interest is still on the error message:

|  Error:
|  incompatible types: inference variable R has incompatible bounds
|      equality constraints: java.util.Optional<T>
|      lower bounds: java.util.OptionalInt, java.lang.Object
|  OptionalInt optional = Arrays.asList(1,2,3,4,55,6,6,7,78,98).stream().collect(Collectors.maxBy(Comparator.comparing(m -> m)));
|                                   ^--------------------------------------------------------------------------------------------------------------------^

 
I have decided to explain it in the way that suits me.  Anybody is free to laugh this time. Even so, I expect that you, being a concerned citizen of this forum, will make corrections to the explanations.
Explanation of error message:
1. incompatible types: inference variable R has incompatible bounds.  // the inference variable in the above statement is OptionalInt opt.  This line of the error message is simply complaining about the fact that the  left hand side of the statement is not compatible with the right hand side.  The right hand side is returning an instance of Optional<Integer> and trying to assign it to a target declared for an instance of OptionalInt.  The solution is either to change the left hand side to Optional<Integer> opt or change the right hand side to return an instance of OptionalInt.
2. equality constraints: java.util.Optional<T>   // meaning the left hand side of the statement should be Optional<T> instead of OptionalInt because the type of variable on the left hand side is constrained by or limited by or dependent on the type of instance returned by the right hand side.
3. lower bounds: java.util.OptionalInt, java.lang.Object   // meaning that left hand side, being the lower bound of the statement, has a definition that says OptionalInt extends Object.  The fully qualified name of OptionalInt is java.util.OptionalInt.  The fully qualified name of Object is java.lang.Object.  The summary is that the two classes are not compatible with the class of instance returned by the right hand side of the statement.  Now, since we already know that OptionalInt opt cannot be the target of an instance of Optional<Integer>, can we try the superclass of OptionalInt instead?  The superclass of OptionalInt is the Object class.  
So,

should work.  However, it does not work, unless the right hand side is cast to Object.  But the statement that caused the error did not cast the right hand side to Object.  So, Java had to report the error.  See next line!


If my self serving explanations are anywhere near correct, then from this point forward, I will look closer at error messages because they actually make a lot of sense.
1 month ago
Thanks to everyone that has responded so far.  However, I will like to return to the error message that formed the basis for this thread.

|  Error:
|  incompatible types: inference variable R has incompatible bounds
|      equality constraints: java.util.Optional<T>
|      lower bounds: java.util.OptionalInt, java.lang.Object
|  OptionalInt optional = Arrays.asList(1,2,3,4,55,6,6,7,78,98).stream().collect(Collectors.maxBy(Comparator.comparing(m -> m)));
|                                  ^--------------------------------------------------------------------------------------------------------------------^


I suppose the inference variable R is talking about OptionalInt optional.  OptionalInt extends Object, meaning the upper bound is Object and the lower bound is OptionalInt.
The right hand side of the assignment statement returns an instance of Optional<T>.  Optional<T> extends Object, meaning the upper bound is Object and the lower bound is Optional<T>.  
I would have thought the lower bounds are java.util.OptionalInt, java.util.Optional
The error message says lower bounds: java.util.OptionalInt, java.lang.Object
Please, explain the concept of lower bounds.
1 month ago
Moderator. It looks like I am seeing double now.  I thought I saw a post from a user named inspire sayan, talking about feedback of Eclipse IDE.  That post has suddenly disappeared.  Did I overwrite it?
1 month ago
I see several mention of IDEs, but I am not using any IDE.  I am using notepad. In fact, I have not used any IDE so far. I can even go a step further to say that I do not know how to use the IDEs yet.  My first priority is to understand the rudiments so that I will not depend on IDEs to tell me the basic things I ought to know.
Going forward, some of the little things are quickly becoming something major, for me, that is.  Example:

I wish to know the full and correct meaning of so that I can write code that uses maxBy() method without relying on IDE to help me out.  Do not laugh!  At this moment, my understanding of ? super T is that it means any subclass of a class.  That is, the class must have a superclass.  The Object class, for example, does not have a super class. That should mean that Comparator<Object> is invalid, but that's not true.

My understanding is flawed.  Now, I appeal.  Who can explain the meaning of ? super T in a simple to comprehend manner?
1 month ago

So, if you only knew that a list is List<Integer> and you have no idea of the actual contents, does it not mean that it is simply unsafe to fetch an item from the list and assign the item to a type other than the Optional type?  What are the benefits of allowing a null in a list?
1 month ago
jshell> Arrays.asList(1,2,null);
$1 ==> [1, 2, null]
|  created scratch variable $1 : List<Integer>
So, what is the meaning of this?  Has null become an instance of Integer?
1 month ago
okay, so:

I am assuming that the lower bound and upper bound is the same thing - Integer.
Now, how does Java infer List<? extends Integer> form Arrays.asList(1,2,3,4,55,6,6,7,78,98) ?
I am also assuming that List<? extends Integer> means a List instance capable of containing instances of  Integer or instances of any subclass of Integer.  
1.  Which is the lower bound - the Integer class or a subclass of the Integer?
2.  Is there any subclass of the Integer class?
1 month ago


Then the following:

|  Error:
|  incompatible types: inference variable R has incompatible bounds
|      equality constraints: java.util.Optional<T>
|      lower bounds: java.util.OptionalInt,java.lang.Object
|  OptionalInt optional = Arrays.asList(1,2,3,4,55,6,6,7,78,98).stream().collect(Collectors.maxBy(Comparator.comparing(m -> m)));
|                                  ^----------------------------------------------------------------------------------------------------^



Now a newbie gets confuse!  Why does OptionalInt not work where Optional<Integer> worked?  Where are the lower bounds in the above command?
1 month ago
Apology.  I relaunched the command prompt and the code runs now.
1 month ago
The Java path has been moved to the to of the list, but problem remains.
1 month ago
Oracle 11g is installed in the computer.  There is no JRE in the path \Oracle\JavaPath.
1 month ago
See my Java Path:
1 month ago