0
Getter setter and array of object in java.
I want some good content about getter setter and array of object in java and is it possible array passing using getter or setter. Please send any content you can any link any code any description.
2 Antworten
+ 1
I was about to write sure you can. But now I have some doubts to just write how you could do it because if you really mean an Object[] this will lead to 'problems' like reflections and should be avoided. Also you need to handle that arrays are static, in this context meaning: fixed size.
I tend to recommend to use a List implementation whenever you need to deal with the limitations of an array. So, here's my advice:
public void addToList(MyElement e) {
this.myList.add(e);
}
public List<MyElement> getList() {
return this.myList;
}
0
example code
https://code.sololearn.com/cM19eWc6AnT5/#java