Can basic types be passed as references in java

In

Java, the method passes parameters, and if the parameter is a basic type, it is passed by value, so can it be passed by reference?

void func1() {
    int a = 1;
    func2(a);
    System.out.println(a); // 1
}

void func2(int a) {
    a = 3;
}

for example: the above code calls func2 in func1, hoping that the value of a can be changed to 3. Can it be implemented in java?
does not go through the return way.

The

function is similar to the following CPP implementation:

void func1() {
    int a = 1;
    func2(a);
    cout << a ; // 3
}

void func2(int & a) {
    a = 3;
}
Apr.02,2021

you can customize a class, such as User, which contains an an attribute.
when passing parameters, modify user.a


1, return (the author asks not to use this method, abandon)
2, upstairs methods
3, an as global variables, in func2, this.a = 3;

Menu