Object cannot be converted to string when using Optional class in Java
问题 I have the following code trying to use the Optional class: import java.util.Optional; // one class needs to have a main() method public class HelloWorld { public String orelesMethod() { return "hello"; } public void test() { String value; value = Optional.ofNullable(null).orElse(orelesMethod()); System.out.println(value); } // arguments are passed using the text field below this editor public static void main(String[] args) { HelloWorld hello = new HelloWorld(); hello.test(); } } when