Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return String from Optional<String>?

Tags:

dialog

javafx

I have the following function.

public String getSomething(){
   TextInputDialog dialog = new TextInputDialog();
   dialog.setHeaderText("X");
   dialog.setTitle("Y");
   Optional<String> result = dialog.showAndWait();
   return result;
}

Obviously, the returned value is not of String type. How could I return a String when result's type is Optional<String>?

like image 379
B.Dave Avatar asked Mar 06 '26 22:03

B.Dave


1 Answers

Try doing result.get() should return a string.

like image 136
Politic Revolutionnaire Avatar answered Mar 10 '26 10:03

Politic Revolutionnaire



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!