Posts πŸ‘€ [Today I Learned] 20210514_TIL
Post
Cancel

πŸ‘€ [Today I Learned] 20210514_TIL

20210514_TIL

μžλ°”(java) Dead Code λž€?


  • VSCλ₯Ό μ‚¬μš©ν•˜λ‹€λ³΄λ©΄ 가끔씩 Dead Code λΌλŠ” λ©”μ‹œμ§€κ°€ 좜λ ₯λ˜λŠ” 것을 λ³Ό 수 μžˆλ‹€.g
  • κ²°κ³Όκ°’ 좜λ ₯μ—λŠ” 별 λ¬Έμ œκ°€ μ—†μ§€λ§Œ, 무엇인지 κΆκΈˆν•΄μ„œ μ°Ύμ•„λ³΄κ²Œ λ˜μ—ˆλ‹€.
  • Dead Code: μ „ν˜€ μ‹€ν–‰λ˜μ§€ μ•ŠλŠ” μ½”λ“œ


λ°œμƒμ›μΈ


  • ex1) λ³€μˆ˜λ₯Ό μ„ μ–Έν•œ λ’€, λ³€μˆ˜λ₯Ό μ‚¬μš©ν•˜μ§€ μ•Šμ•˜μ„ λ•Œ ν•΄λ‹Ή λ³€μˆ˜λŠ” Dead Codeκ°€ λœλ‹€.

image


  • ex2) μ‘°κ±΄λ¬Έμ—μ„œ ifκ°€ λ³€μˆ˜μ— λŒ€ν•΄ 항상 trueλ₯Ό λ§Œμ‘±ν•  경우 false μΌλ•Œ μˆ˜ν–‰ν•˜λŠ” elseλŠ” dead codeκ°€ λœλ‹€.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package etc;

    /*
     * dead_code
     */

    public class dead_code {
        public static void main(String[] args) {
            
            int num1 = 1;  // Dead Code (μ„ μ–Έ ν›„ μ‚¬μš©λ˜μ§€ μ•Šμ€ λ³€μˆ˜)

            int num2 = 2;
            System.out.println(num2);

            if (num2 > 1) {
                System.out.println('T');
            }

            else {         // Dead Code (쑰건문의 κ²°κ³Όκ°€ 항상 'T' μ΄λ―€λ‘œ)
                System.out.println('F'); 
            }
        }
        
    }
This post is licensed under CC BY 4.0 by the author.

😸 [Git] git add -p μ˜΅μ…˜

β˜•οΈ [Java] 30일 μ•ˆμ— 기초 λ–ΌκΈ°/ DAY-08