I have a method that can return null if a condition of the parameter is met. For example
public static ObjectA newObjectA(String param) {
    ObjectB objB = new ObjectB();
    ObjectA objA;
    if (param == null) {
        return null;
    }
    // do something else
    return objA;
}
Is it better if I move the initialization of objB after checking the null if (param == null)? It will be like this:
public static ObjectA newObjectA(String param) {
    ObjectB objB;
    ObjectA objA;
    if (param == null) {
        return null;
    }
    objB = new ObjectB();
    // do something else
    return objA;
}
Is there any improvement like avoiding memory usage for objB? Or is it even better if I move the declaration of the objects after checking null param like this?
public static ObjectA newObjectA(String param) {
    if (param == null) {
        return null;
    }
    ObjectB objB = new ObjectB();
    ObjectA objA;
    // do something else
    return objA;
}
Thank you guys.
 
    