【发布时间】:2015-11-04 14:15:14
【问题描述】:
对我来说很清楚这个问题的答案是NO,但就在今天我来了
Context.setCredentials(userId, pwd.toCharArray());
其中 setCredentials 是非静态方法。 Intellij IDEA 将此突出显示为错误,因此我的项目没有编译,但是,在 Eclipse 中一切正常,它怎么会?
解决问题不是问题,但我想了解为什么会发生这种情况。附:我可能会认为这可能是特定于项目的。
更新
在调用 setCredentials 之前,会发生另一个调用:
Context.initContext()
我们在哪里调用了以下方法:
synchronized private static void initContext(String connectionString) {
if (_this == null) {
_this = new Context(connectionString);
}
}
this 在同一个 Context 类中定义如下:
private static Context _this;
似乎它可以工作,如果我们的实例被创建,Eclipse 显示它正确,但是,它在类中,非常奇怪的代码。
【问题讨论】:
-
发布
Context对象的代码 -
不,这是不可能的。清理你的 Eclipse 项目,它可能很混乱。
-
确实如此。甚至创建字符串用户; if(user == "") 将产生错误。必须启动变量。
-
好的,我清理了我的项目,但它仍然解决了所有问题,并且在 Eclipse 中没有显示此行的错误。
-
我认为可以在 lambda 表达式中传递非静态方法。例如,
String::length。
标签: java eclipse intellij-idea