我有以下问题:如何上溯造型和使用童工的具体方法
//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,你的方法似乎是最合乎逻辑的,如果你有超过DepartmentType
& OrganizationType
控制。不幸的是,这些对象是由xmlbeans从XML模式生成的。在我的情况下,我可能重新设计架构,使这两种类型都有共同的基础。
但是如果我不能控制架构会怎么样。我怎么能实现这个基本想法?
这就是问题所在,我无法控制'DepartmentType'&'OrganizationType',它们是由xml中的xmlbeans生成的。 – zeldi 2011-04-04 21:12:41