I thought bad thing would happen when I ended a line like this. But compiler didn\'t even complain. Does anybody have an idea, why this is legal in java.
displ
Here's a practical example in C:
#ifndef NDEBUG
#define Dprintf printf
#else
#define Dprintf(X)
#endif
if(some_test)
Dprintf("It's true!");
else
Dprintf("It's false.");
If NDEBUG
is defined, the compiler will see:
if(some_test)
;
else
;
This can be useful in some cases.
Since Java is heavily inspired by C/C++, it's something they kept, even though it is not useful and there is no preprocessor.
You can, if you want, run the C preprocessor cpp
on your code to do this kind of behaviour.
Some languages may say it's an error instead, it's up to them to choose.