简体   繁体   English

Java,迭代一个对象

[英]Java, iterate over an object

I have some JAVA code like the next:我有一些 JAVA 代码,如下所示:

public class DataModel {
  public DataModel(OtherDataModel someObject) {
    System.out.println(someObject);
  }
}

Debug Output:调试输出:

someObject
--someOtherObject
--ArrayList (related to someOtherObject)

I need to iterate over someObject to get an output like this:我需要遍历 someObject 以获得这样的输出:

someOtherObject
-id
-name
-dates (of ArrayList)
--date1
--date2
--dateN
-description
-etc

What is the best way to do this?做这个的最好方式是什么?

From main method, create an object of your class and past that object as a parameter.从 main 方法中,创建类的对象并将该对象作为参数传递。 After that you can access the properties of the object by using getting method.之后,您可以使用getting 方法访问对象的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM