You can use Objects.toString() (standard in Java 7):
Objects.toString(gearBox, "")
Objects.toString(id, "")
From the linked documentation:
public static String toString(Object o, String nullDefault)Returns the result of calling
toStringon the first argument if the first argument is not null and returns the second argument otherwise.Parameters:
o– an object
nullDefault– string to return if the first argument isnullReturns:
the result of callingtoStringon the first argument if it is notnulland the second argument otherwise.See Also:
toString(Object)