How can I declare an object without having instantiated it?

0

I came across a question in android programming when declaring the Views in the java class, as in the example: (TextView txt = (TextView) findViewById (R.id.txt)), this View is being used by the class without before have you been instantiated?

    
asked by anonymous 24.01.2018 / 20:37

1 answer

3

I think you're confusing declare with initialize / assign.

On line

TextView txt = (TextView) findViewById (R.id.txt);

The declaration is being made through

TextView txt

and at the same time the assignment, through

= (TextView) findViewById (R.id.txt)

Views are instantiated by Activity during the process of its creation. The findViewById(R.id.txt) method takes care of returning the instance of the view whose id is R.id.txt , if any.

    
24.01.2018 / 21:42