java-gi
java-gi copied to clipboard
Return out-parameters when the function returns void
When a function returns void or boolean, and has only one visible "out" parameter that isn't optional (no optional=0 GIR annotation):
- Set the return type to the out-parameter type
- Hide the out-parameter from the method signature
- Generate a preprocessing line that will allocate the out-parameter
- Return the out-parameter (either with a postprocessing statement or otherwise)
For functions that return boolean it is strictly incorrect to discard that value, but it is usually only an indication that an error has occurred. But that is not necessary in Java because an exception will be thrown in that case.
See g_file_load_contents for an example: the function returns boolean to signal an error, the contents parameter is not optional, count is an array length parameter so it is hidden, and etag is optional. The Java method could in this case return contents, leaving etag as an out parameter.