私は次の問題を抱えています:
//class XmlObject is part of org.apache.xmlbeans
public class DepartmentType extends XmlObject; // getName method is defined in this class
public class OrganizatiopnType extends XmlObject; // getName method is defined in this class
XmlObject department = null;
if (a == 1)
department = (DepartmentType) order.getDepartment(); // returns DepartmentType
else
department = (OrganizationType) order.getOrganization(); // returns OrganizationType
department.getName(); // throws cannot find symbol
// ... and do some other complex stuff using methods which are defined in both classes ...
getName()メソッドを呼び出す最もクリーンな方法は何ですか?
更新1: Cybernate、 &
を制御できる場合、あなたのアプローチは最も論理的であるように思われます。残念ながら、これらのオブジェクトはxmlbeansによってXMLスキーマから生成されます。私の場合、両方のタイプが共通ベースを持つようにスキーマを再設計できます。DepartmentType
OrganizationType
しかし、スキーマを制御できない場合はどうなりますか。基本的な考え方をどのように実装できますか?