Hi, I asked this question in the beginner's forum and people seem to think I am crazy, so I'll try here. This is a problem out of Scott's "Programming Language Pragmatics". Can anyone one give me an example of an error in Java that would not be caught at compile time or run-time. I'm not talking about a logical error but a violation of the language definition, ie. a syntactic or semantic... or I guess even lexical error. Any input would be deeply appreciated. Thanks, Thomas
The programmer surely meant to write "b == true" but since the result of the assignment is a boolean, the compiler misses this error. This can happen in C/C++ much more often, because C doesn't have a boolean type. There's an easy way to avoid this problem by the way: never compare to a boolean literal. The above condition could be written "if (b)" and the error then would never happen.