Issue
I am extremely new in Java and computer programming in whole. Today I came across a line shown as:
assertThrows(IllegalArgumentException.class, () -> add(x, 2));
where x is an integer.
I am confused on the add() method inside of the assertThrows(), does this mean add() will be executed? Also, what exactly does add() do? There are two objects inside the bracket, will both be added?
Thank you very much! Any help is greatly appreciated.
Solution
The second parameter in that method is a lambda function. In the context of assertThrows
it is a method that is supposed to throw an exception of class IllegalArgumentException
. Here are some examples and a bit more info on what a lambda expression is.
Answered By - Hawkeye5450
Answer Checked By - Clifford M. (JavaFixing Volunteer)