LoginSignup
51
52

More than 5 years have passed since last update.

コメントによるコードの切り替え

Last updated at Posted at 2014-04-05

2種類のコードを書いて、切り替えながらコーディングしたい場合がある。
ブロックコメントとラインコメントを利用して、1文字入れたり消したりするだけで簡単にコードを切り替える方法

自分用にソース書きながら比較する程度なら良いですが、これコミットしたりすると迷惑なのでやめましょう。

例えば、こんな感じで書くと、コード1が有効になる。

/**/
System.out.println("コード1");
/*/
System.out.println("コード2");
//*/

最初の行のブロックコメントを閉じている部分にスペースなどを入れると、コード2が有効になる。

/** /
System.out.println("コード1");
/*/
System.out.println("コード2");
//*/

SQLもできる

SELECT *
FROM shop
WHERE
/**/
shop_id = 1
/*/
shop_id = 2
-- */
51
52
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
51
52