Stephan van Hulst

Saloon Keeper
+ Follow
since Sep 20, 2010
Enschede, The Netherlands
Cows and Likes
Cows
Total received
172
In last 30 days
3
Total given
166
Likes
Total received
1882
Received in last 30 days
45
Total given
192
Given in last 30 days
4
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Stephan van Hulst

In Dutch the words are 'wijdte' and 'breedte'. They are interchangeable, but I think 'breedte' is used more often.
17 hours ago
Well, what do you think that line 5 means, if it were valid?
Yes, but only if the first argument of the functional interface is of the type that you want to apply the method reference to.

You might find it helpful to rewrite method declarations and functional interfaces as a canonical type expression. I use a form of lambda calculus that is prevalent in languages like Haskell.

BiPredicate<Integer, Integer> represents a function that takes two integers and returns a boolean. You can write it as Integer -> Integer -> boolean.

MyClass.evaluate() is a function that takes two integers and returns a boolean, but it also takes a MyClass because it's an instance method. You can write it as MyClass -> Integer -> Integer -> boolean.

Method handles can be written as an operation on a class name, or as an operation on an object reference. When you operate on the class name, you get the full type expression of that method, so MyClass::evaluate is a MyClass -> Integer -> Integer -> boolean. As you can see, this is not compatible with the BiPredicate.

When you operate on an object reference, the type expression is the same, except you omit the first operand. obj::evaluate is an Integer -> Integer -> boolean. This is compatible with the BiPredicate.

You can juggle around with this. When a higher order function accepts an X -> Y -> Z, you can pass it all of the following handles:

X::instance_Method_Accepting___Y_Returning_Z
W::static___Method_Accepting__XY_Returning_Z
w::instance_Method_Accepting_WXY_Returning_Z
19 hours ago
Welcome to CodeRanch!

BiPredicate<Integer, Integer> represents a function that takes two integers and returns a boolean. MyClass.evaluate(int, int) is a function that takes a MyClass and two integers, and returns a boolean, so it doesn't fit.

You can still make it compile using a method reference though, by supplying an object to the method reference:
22 hours ago
Yes.

I'm not aware of any technical reasons not to implement this in the language, maybe the designers wanted to keep things simple. The current situation really annoys me though.
Do you have examples of specific tags that you're unsure about?
1 day ago
I don't know, but why would you want to do that if you can just create a batch script for each environment? Do you have a good reason not to use scripts or shortcuts?
1 day ago

Stephan van Hulst wrote:I wish that virtual methods had the same access level as the interface they were declared in, whether or not you specify that access level explicitly.


a.C wouldn't be able to implement b.I unless b.I was public, and if it's public, its virtual methods would be public as well.
They didn't downvote your answer because the question was unclear, but because you seem to pull the answer out of thin air without explaining how you got it, or why it works. When people ask for help, it's better to teach them how to solve the problem for themselves than it is to give them an answer that is only helpful in a very specific case.

I'm not saying that I agree with the treatment you got there, I'm just explaining why you were treated that way.

I don't think you're going to get your answer upvoted again by making another question about it, it's better to just move on I guess.
1 day ago
Why not just create a shortcut or batch script that supplies the JVM arguments?
1 day ago

Campbell Ritchie wrote:If you aren't using Java10‑type private methods, then all interface methods are public and must only be overridden with public access.


This is actually one of by biggest peeves about Java. I wish that virtual methods had the same access level as the interface they were declared in, whether or not you specify that access level explicitly.

Let's say I have a package containing a package private interface, because that interface is only used within the package. It also contains a public class that implements that interface. As it stands, my class MUST expose the methods declared in the interface, even though I would have liked them to remain private to the package.
To further clarify what PaweĊ‚ wrote, the value you are using to create the BigDecimal instance with is not actually -0.206, but the closest value that can be represented by the double datatype.
2 days ago
This works for ALL classes, not just test classes:


3 days ago
I think you can compare a call to scanner.nextLine() to the following sequence of calls:
3 days ago