[英]How to create child object in java (android)
我是 php 開發人員,我是 Java 新手。 我只想在java中創建一個多級對象並為其分配值。 請看一下對象。
Object = {
0 : {
name : abc,
description : xyz,
},
1 : {
0 : {
name : abc1,
description : abc2
}
1 : {
name : abc
description add,
}
}
}
首先,你需要通過定義一個類來創建一個對象
例子
class XYZ {
//constructor to initialize value
XYZ(X detail, Y information){
this.detail = detail;
this.information = information;
}
X detail;
Y information
}
class X {
//constructor to initialize value
X(String name, String description){
this.name = name
this.information = information
}
String name;
String description;
}
class Y {
//constructor to initialize value
Y(X first, X second){
this.first = first;
this.second = second;
}
X first;
X second;
}
並分配默認值使用構造函數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.