Roland Szép Roland Szép - 6 months ago 15
Android Question

What is the better way to define TextView?

What is the better way to define TextView?

private TextView mytextview1;
private TextView mytextview2;
private TextView mytextview3;


or

private TextView mytextview1, mytextview2, mytextview3;

Answer

What u really asking is how the variables in java can be declared.

ideally the Java compiler will do an optimization on your first option

private TextView mytextview1;
private TextView mytextview2;
private TextView mytextview3;

reduce it to second option, so inside the compiler both your options lead to same result. Furthermore since most of the TextViews will not be assigned again the compiler will make those variables final as well. Check this for further clarifications final variable optimizations

Comments