Forwarding of objects in Android (Java)?Reference...?

Asked 2 years ago, Updated 2 years ago, 27 views

Um...

I'm studying Android right now and I'm asking you a question because I'm confused

Situation? To explain

Class mainActivity extends Activity {
    A a = new A(this); 
}
Class A{

    Activity activity;
    B b;

    public A( Activity activity){
        this.activity = activity;
    }

    b = new B(activity);

}
Class B{

    Activity activity;


    public B( Activity activity){
        this.activity = activity;
    }

In this state, does the activity variable of object a and object b refer to the same object?

Um... I know that an object of a class other than the normal type (int, float, char, etc.) has an address value and that address value is the address of the object, but since it passed itself from mainActivity to this, is mainActivity, a, b the same?

If it is the same, does the capacity occupy only one main activity capacity instead of the size * 3 of the main activity class?

I don't know how to explain it. It's very complicated <

----------------------------------------------------------------------------------------

I don't know if it's right or left here.

android java

2022-09-21 19:25

1 Answers

It is understood that you have questioned the variable reference problem in the Java language.

Java is a reference type except for the primitive type int,char,... (lower case). You are right to understand that the reference type refers to the memory where the actual object is stored.

It's going to look like the left side of the painting.


2022-09-21 19:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.