Issue
For me it was very clear that the answer to this question is NO, but just today I came to the line
Context.setCredentials(userId, pwd.toCharArray());
where setCredentials is non-static method. Intellij IDEA highlights this as an error, thus my project wasn't compiling, however, in Eclipse everything is building fine, how it can be?
It is not a problem to fix the issue, but I would like to understand why this can happen. P.s. I might assume that this can be very project specific.
UPDATE
Before setCredentials is called there is another call happens:
Context.initContext()
where somewhere we invoke the following method:
synchronized private static void initContext(String connectionString) {
if (_this == null) {
_this = new Context(connectionString);
}
}
where this
is defined like this in the same Context class:
private static Context _this;
Seems that it might work and Eclipse shows it right if our instance is created, however, it is inside the class, really weird code.
Solution
Ok, the answer is clear NO, but now I will try to explain why it happened this way. In reality here there is nothing to be done about Java, it is more about the IDE, but more about project settings.
The project was originally developed in Eclipse, however, during my try to build it in Intellij IDEA I didn't include the Eclipse project settings, thus IDEA recognized it as sources and tried to compile. That's why it complained.
So, the thing is that in Eclipse the folder with this class was included in sources, however, all the files were excluded in the same time. Thus the compiler was not including this file and Eclipse doesn't show the error. I would like to notice that because I didn't have much experience with Eclipse it was extremely difficult to find it out plus I didn't recognize the following difference between the source files icons:
However, in Intellij IDEA it could be recognized a bit faster, I think:
I think that it is good to make a conclusion about this situation: don't exclude any files from your source folders if you don't have very specific reason. If this code is not maintained, it is better just to remove it or move it somewhere else.
Answered By - Rufi
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)