Background
I am working with functions which which passes arguments as pointers. I need to convert a function which is written in C to JAVA with the same behavior as in C. I am developing for Android in Eclipse under Windows.
C Function Example
int testFunction( char* firstName, char* SecomdName, char* lastname, int age);
This function takes 3 pointers to char values and initializes them, so in C I can write something like the following to initialize all three pointers:
char* v1, v2, v3;
int res = testFunction(v1, v2, v3, 54);
After the call to testFunction, the variables v1, v2, v3 will be initialized with some values.
JAVA Function Example
int testFunction( String firstName, String secondName, String lastName, int age);
This is the same function as in C but written in JAVA, however in JAVA there are no pointers which means that I can’t write something like this:
String v1, v2, v3;
testFunction(v1, v2, v3, 54);
Question:
What can I do to get the same initialization behavor for my JAVA function as in the C example? Is this possible?
There’s a few things you could do. You could create a bean class that contains the fields you want to create, ie something like:
Your testFunction could then instantiate a Names object and return it, ie.
An alternative, if you’re dealing with Strings is to pass through StringBuilder objects, ie
Then elsewhere in your code you could use…