I encountered a weird function call which is shown below:
addData("abc", "abc" {
public boolean isDataCorrect() {
return true;
}
});
addData signature is
public void addData(String a, String b);
Can anyone explain whats the code in curly braces doing? Moreover how is it even working?
That doesn’t compile.
Probably you’re seeing which does not longer exists.
For instance suppose that the
addDatamethod use to receiveString a , OtherClass bLater on, the OtherClass was substituted by String and in an automatic re-factoring, that came, something like:After refactoring, someone ( probably a bad refactoring tool ) thought the raw string could be used.
When you compile it and run it, it doesn’t even compile, but since it was running before, the run script takes the previous version ( the one using AbcValidator ) and looks like it is working, but it is not.
It is almost impossible to guess what is happening in your desk, but make no mistakes, that doesn’t run.
To probe it do the following:
A) create a new directory and a java “Hey.java” with the following contents:
B) Compile that file, preferably from the command line:
javac Hey.javaYou’ll see it doesn’t works.