Skip to content

Tag: lambda

Using links to static and non-static methods with interface

Why I can call non-static method length() from class String, but I can’t call non-static method lengthHelper( String line ) from my class ExpressionHelper? Answer String::length is an instance method of String. It requires an instance of String to run, which you are providing, because you are passing el…

reusing stream inside a stream java

Hi I just wanted to know what is wrong with my code and how can I improve it as it throws an error “stream has already been operated upon or closed” thank you here is my code: I wanted to loop inside the file and check per line if the characters there exceeded 12 characters or not Answer You canno…

Can I use a lambda function like this?

I want to try to use lambda functions (which I do not understand well) so I can learn more about them. I have an assignment on trees that has us making a family tree class. children is a set of all of the children nodes to this node. Also as a side question, does this usage of AtomicInteger work similarly

Java does not catch exception

I am trying to implement lambda expression for constructor. My constructor can throw an IllegalArgumentException. I tried different ways. First way is just calling lambda expression: It works perfectly fine, I can catch Exception and then parse it. The problem occurs when I try to use my own interface: and th…