Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这样的课程:
Class A extends B Class B extends C Class C{ protected ArrayList<Dialog> variable; }
而我想做A类的JUnit测试,我想得到C类中变量的实例,有没有办法做到这一点?
非常感谢。
您必须将 getter 和 setter 添加到 B 类,然后您可以像这样访问 A 类中的变量
class C{ protected Object variable; } class B extends C{ protected void setObject(Object obj) this.variable = obj; } protected Object getObject(){ return this.variable; } } class A extends B{ }