I assume you want to comment on the embedded code for debugging or testing, right? Because leaving huge blocks of code with comments in production code is usually considered very bad.
Nested comments are not originally a java function. So what can you do? Here are a few options:
Insert comments Slash Slash . The best I could come up with was to use an editor that has a hotkey so that slashslash comments out the entire block of code, since // can be nested. Eclipse and Netbeans have such support, although there are slight differences in how it works between the IDE, as far as it decides to switch comments against their nesting. Usually nested // comments can be executed until the selection is identical.
third-party preprocessor . However, J2ME uses the pre-processor in eclipse, but I don't think that would help with java desktop. It seems like other preprocessors written for or compatible with eclipse if you are looking for them. However, this will definitely impede portability, as this is not a standard Java feature.
edit comment Another thing that I often did for a quick nested need for comments (moreso in css that doesn't // make comments than java though) is to add a space between the last two characters ending the inner comment */ , so java will not complete the outer comment at the inner end of the comment. It is not too difficult (but a little manual) to restore the original comment. The nested /* is usually ignored by the parser based on how it matches its pattern. Eg / * code / * nested comment * / more code * / `
use version control . You can also easily use most version control systems to keep a copy of your code with remote code. And then later use the restore / diff / merge version control tool to return your remote code. As a rule, this decision is considered the best style. Especially if this commented code is needed for this for a long time.
if (false) If your code that you want to use does not allow you to run both compilers and is within the same function, you can easily disable it by adding an if statement to it, you will never be right, for example if (false) { ... } Obviously, this will never pass any tool for checking code like lint, but its quick and easy ;-)
source share