CATEGORII DOCUMENTE |
Asp | Autocad | C | Dot net | Excel | Fox pro | Html | Java |
Linux | Mathcad | Photoshop | Php | Sql | Visual studio | Windows | Xml |
One of the pitfalls when using operators is trying to get away without parentheses when you are even the least bit uncertain about how an expression will evaluate. This is still true in Java.
An extremely common error in C and C++ looks like this:
while(x = y)
The programmer was trying to test for equivalence (==) rather than do an assignment. In C and C++ the result of this assignment will always be true if y is nonzero, and you'll probably get an infinite loop. In Java, the result of this expression is not a boolean, and the compiler expects a boolean and won't convert from an int, so it will conveniently give you a compile-time error and catch the problem before you ever try to run the program. So the pitfall never happens in Java. (The only time you won't get a compile-time error is when x and y are boolean, in which case x = y is a legal expression, and in the above case, probably an error.)
A similar problem in C and C++ is using bitwise AND and OR instead of logical. Bitwise AND and OR use one of the characters (& or |) while logical AND and OR use two (&& and ||). Just as with = and ==, it's easy to type just one character instead of two. In Java, the compiler again prevents this because it won't let you cavalierly use one type where it doesn't belong.
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 771
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved