I am using Gson to parse Json. What I don't understand what the return type will be if you don't catch the Runtime Exception. I was expecting it to be null
, but it is not null
when evaluating with a simple if
statement.
My code looks something like this:
public X x(final String jsonString) {
return gson.fromJson(jsonString, X.class);
}
then from another function I call the function:
public void y() {
final X x = x();
if (x == null) {
System.out.println("x == null");
}
}
I was expecting x to be null, but it isn't because the print statement is not called? What is the value of x
? I have solved my problem by using a catch block in the x()
function and returning null
from inside the catch block. But I am just wondering what the value of function x()
is(if any?)? Hopefully I make any sense at all.