With the question of passing an object as a parameter by value, everything seems to be clear - in the example below, the code in the actionTimer method actionTimer not affect the timer object [0].
But the question arises, how can you solve such a problem - work with the same type of objects in the same way, using the same method? Those. What working alternatives can be used to implement the problem solved in the code below?
public class MainActivity extends Activity { private Timer []timer = new Timer[10]; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mainactivity); actionTimer (timer[0]); } private void actionTimer (Timer localTimer) { localTimer = null; localTimer = new Timer(); } } Or is there only one solution - for each object to use its own method, for example, as in the code below?
actionTimer1 (); } private void actionTimer1 () { timer[0] = null; timer[0] = new Timer(); }
actionTimermethodactionTimerchangetimer[0]then pass 2 incoming parameters - thetimerarray andintindex 0. - anber