How to put new object in the array in the constructor of class?

Issue

public Tasks(int linkToDiolog, int reward, Weapon weapon, int q) {
    this.linkToDiolog = linkToDiolog;
    this.reward = reward;
    this.weapon = weapon;
    this.q = q;
}

I need to put new object in the array list like this:

public Tasks(int linkToDiolog, int reward, Weapon weapon, int q) {
    this.linkToDiolog = linkToDiolog;
    this.reward = reward;
    this.weapon = weapon;
    this.q = q;
    listOfTasks[q] = new Tasks(linkToDiolig, reward, weapon, q);  
}

I know that this will lead to an infinite loop, but I hope you know how the code can be lightened and unloaded in a different way.

Solution

Create another method in Tasks class to create new Tasks object and call it from activity where you created the class object.

Answered By – Harshit singhal

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published