我正在寻找一种简洁优雅的方法来根据变量值将对象变量转换为数组。
例子:
public class Subject {
public Subject(boolean music, boolean food, boolean sport, boolean business, boolean art) {
this.music = music;
this.food = food;
this.sport = sport;
this.business = business;
this.art = art;
}
private final Long id;
private final boolean music;
private final boolean food;
private final boolean sport;
private final boolean business;
private final boolean art;
}
根据每个字段的值,我想将字段名称作为字符串添加到数组中。
例子: new Subject(true, true, true, false, false)
预期结果: ["music", "food", "sport"]
PIPIONE
慕虎7371278
千巷猫影
相关分类