【发布时间】:2012-02-22 14:21:23
【问题描述】:
目前我有一个类正在调用另一个类的静态方法。然而,我想要做的是让静态方法更改调用类的变量,这可能吗?
示例代码:
public class exClass {
private int aVariable;
public exClass() {
othClass.aMethod();
}
}
public class othClass {
static void aMethod() {
// stuff happens, preferably stuff that
// allows me to change exClass.aVariable
}
}
所以我想知道的是,是否有一种方法可以访问调用 othClass 的 exClass 实例的变量。显然,除了使用 return 语句。
【问题讨论】:
-
嗯...你为什么要这个? return 语句有什么问题?
-
代码只是示例性的。我已经在退货了。由于我使用的类都是静态的,很明显我不能只将变量保存在类本身中并编写一个get方法来获取我想要的信息给类调用。
-
这可能是一个例子,但我不会称之为典范。
-
啊,好吧,英语不是我的第一语言。用我的语言这么说更有意义! ;)