我正在创建一个有趣的Android应用程序来跟踪支出。我正在使用Room来保留用户的数据,并且有一些POJO可以显示每日/每周/每月摘要。这些类非常相似,因此我希望有一个抽象的POJO,其中包含重新格式化为正确格式的字段和扩展。就像是:public abstract class PeriodInformation {PeriodInformation(@NonNull Calendar mCalendar, Integer mPeriodSpendingCount, Float mPeriodSpendingSum) { this.mCalendar = mCalendar; this.mPeriodSpendingCount = mPeriodSpendingCount; this.mPeriodSpendingSum = mPeriodSpendingSum;}@ColumnInfo(name = "DateTime")private final Calendar mCalendar;@ColumnInfo(name = "SpendingCount")private Integer mPeriodSpendingCount;@ColumnInfo(name = "SpendingSum")private Float mPeriodSpendingSum;// Some other code, e.g., getters, equal override,...}这里的扩展名:public class WeekInformation extends PeriodInformation{public WeekInformation(@NonNull Calendar mCalendar, Integer mPeriodSpendingCount, Float mMonthSpendingSum) { super(mCalendar, mPeriodSpendingCount, mMonthSpendingSum);}@Overridepublic String getPeriodRepresentation() { //return representation;}}但是,对于WeekInformation类,我收到以下错误消息:错误:实体和Pojos必须具有可用的公共构造函数。您可以有一个空的构造函数或一个其参数与字段匹配的构造函数(按名称和类型)。因此,这似乎在Room中是不可能的,因此,我很乐意得到一些建议,即如何不必过于频繁地复制相同的代码。
添加回答
举报
0/150
提交
取消