There’s a way to iterate the member variables of an object in Java?
I have this scenario:
class ItemToUpdateTipo0 {
public String ticker;
public ItemToUpdateTipo0() {
}
public ItemToUpdateTipo0(String ticker) {
this.ticker = ticker;
}
}
public class DataStoreTipo0 {
private Queue <ItemToUpdateTipo0> QueueItemToUpdateTipo0 = new ConcurrentLinkedQueue<ItemToUpdateTipo0>();
...
}
There’s a way to do something like:
public static void main(String[] args){
DataStoreTipo0 dataStoreTipo0 = new DataStoreTipo0();
for (ItemToUpdateTipo0 obj : dataStoreTipo0) {
System.out.println(obj.titolo);
}
}
Thanks in advance.
Have your class implement the Iterable interface for this to work.
e.g.,
Note that you’ll want to edit your code so that it follows Java naming conventions. For instance classes should start with upper-case letters while methods and fields should start with lower-case letters. You’ll also not want to try to directly access ItemToUpdateTipo0’s fields but rather use public getter and possibly setter methods to do this for you.