我有以下模型:
abstract Article {id, name, text}
final NewspaperArticle { printDate } extends Article
final ScientificArticle { quotations, publicationDate } extends Article
final ... { ... } extends Article
我想知道如何在彼此之间实现最终实体的转换,以便设置 Article 超类的公共字段并且不同的字段保持为空。就像是:
ScientificArticle scientificArticle = ...;
NewspaperArticle newspaperArticle = new NewspaperArticle();
newspaperArticle.copyOf(scientificArticle);
是否可以投射它或者我将不得不使用反射?