I come from a C++ background and I can't figure out how to do this in Java.
There doesn't seem to be a concept of passing int by reference. The & doesn't exist as a reference operator so
does not work. I can pass a class in, ending up with something like
This seems unduly complicated. I've been browsing the net for the past few hours. I can't find an example that returns any basic type. All the examples in books and on the net only return objects.
Am I missing something? All I want to do is return some basic types.
Code:
void twice(int& a, int& b)
{
a += a;
b += b;
}
Code:
void twice (int a, int b)
{
a += a;
b += b;
}
Code:
public class IntByRef
{
public IntByRef () {}
public int value;
}
...
void twice(IntByRef a, IntByRef b)
{
a.value += a.value;
b.value += b.value;
}
Am I missing something? All I want to do is return some basic types.