Java Reference
In-Depth Information
doesn't even compile. Let's take another look at the relevant section, this time highlighting the block
comment in boldface:
if ("abcdefghijklmnopqrstuvwxyz".indexOf(ch) >= 0)
return "LETTER ";
/* (Operators not supported yet)
if ("+-*/ &|!=".indexOf(ch) >= 0)
return "OPERATOR ";
*/
return "UNKNOWN ";
}
}
As you can see, the comment ends inside the string, which quite naturally contains the characters
*/ . The resulting program is syntactically invalid. Our attempt to comment out a section of the
program failed because string literals are not treated specially within comments.
More generally, the text inside of comments is not treated specially in any way [JLS 3.7]. Therefore,
block comments do not nest. Consider the following code snippet:
/* Add the numbers from 1 to n */
int sum = 0;
for (int i = 1; i <= n; i++)
sum += i;
Now suppose that we try to comment out the snippet with a block comment. Again, we highlight
the entire comment in boldface:
/*
/* Add the numbers from to 1 to n */
 
 
Search WWH ::




Custom Search