I have a snip code using lambda, but got error
"target type of a lambda conversion must be an interface".
Anyone can help? My code is as follows:
private By optStarGrade = (strStar) -> { By.xpath("//input[@id='" + strStar + "'"); };
By is a class, so it cannot be used as a target type for a lambda expression.
Only interfaces with a SAM (Single Abstract Method) can be used as target types for lambda expressions.
So, if you really wanted to use a lambda, then use a Consumer<String>:
private Consumer<String> optStarGrade = (strStar) -> {By.xpath("//input[@id='" + strStar + "'");};
if you don't want to ignore the returned value from By.xpath then use Function<String, By>
private Function<String, By> optStarGrade = (strStar) -> By.xpath("//input[@id='" + strStar + "'");
See the Function and Consumer functional interfaces for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With