Is there a proficient way to set a string to some default value if assignment gives nullPointerException?
Say im initializing a string like this:
String myString= jsonElement.getAsJsonObject().get("myString").getAsString();
If it gives nullPointer i need to give it a default value, i know i can do it with an "if" check after but is that the only way? It would mean alot of checks as i am initiating around 20 strings.
Is there any way to do it like:
String myString = jsonElement.getAsJsonObject().get("myString")
.getAsString() || "defaultValue";
getAsJsonObject()?getAsJsonObject()is a JsonObject