I am new to Java-8 and appium and trying to write my webdriver code in Java-8 as mentioned below
Currently below code is working fine but I don't want to write Function and Consumer in separate lines as mentioned below in lines line 5 and line 6 and i want to optimize the code more i.e something like Function within Consumer or Consumer within Function.Thanks! in Advance
public class Gestures_Drag_And_Drop {
AndroidDriver<AndroidElement> driver;
Function<String, AndroidElement> F = driver::findElementByXPath;//line 5
Consumer<AndroidElement> C = AndroidElement::click; //line 6
Gestures_Drag_And_Drop() {
C.accept(F.apply("//android.widget.TextView[@text='Views']"));
}
public static void main(String[] args) throws MalformedURLException {
new Gestures_Drag_And_Drop();
}
}
Your function or consumer variable not need to be just method reference, you can define whatever method body you want using lambda expressions. I guess you asking for something like this:
BiConsumer<String, WebDriver> findAndClick = (locator, webdriver) -> webdriver.findElement(By.xpath(locator)).click();
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