Final

Final , Finalize , Finally

Final

In class : ์ƒ์†์„ ๋ฐ›์„ ์ˆ˜ ์—†๋‹ค

public final class JunnyLand {
    public void joinus(){}
}
class sample extends JunnyLand{ } << X

In Method : ์˜ค๋ฒ„๋ผ์ด๋”ฉ ํ•  ์ˆ˜ ์—†๋‹ค

public class JunnyLand {
    public final void joinus(){}
}

class sample extends JunnyLand{
    @Override
    public void joinus() {} << X
}

In Field : ์žฌํ• ๋‹น ํ•  ์ˆ˜ ์—†๋‹ค

public class JunnyLand {
    private final Long hello= 1L;
    public void joinus(){
        hello = 2L; << X
    }
}

Finally

try-catch์ดํ›„์— ํ•ญ์ƒ ์‹คํ–‰๋˜๋Š” ๋ธ”๋ก์„ ์ง€์ •ํ•ด์ค๋‹ˆ๋‹ค. AutoCloseable, try-catch-resource๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์„ ์ถ”์ฒœํ•œ๋‹ค

public class JunnyLand {
    public void joinus(){
        try {
            System.out.println("Hello, JunnyLand!");
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            System.out.println("Bye, JunnyLand!");
        }
    }
}

Finalize

GC๊ฐ€ ๋”์ด์ƒ ์ฐธ์กฐํ•˜์ง€ ์•Š๋Š” ๊ฐ์ฒด๋ฅผ ๋ฉ”๋ชจ๋ฆฌ์—์„œ ์ฐธ์กฐ ํ•ด์ œํ•  ๋•Œ ํ˜ธ์ถœ๋œ๋‹ค. GC์‹œ ํ•˜๋Š”์ผ์„ ์ปค์Šคํ…€ํ•˜๋Š” ๊ฒฝ์šฐ ์‚ฌ์šฉํ•˜์ง€๋งŒ, Deprecated ๋˜์—ˆ๊ณ  ์‚ฌ์šฉํ•  ์ผ์€ ์—†๋‹ค.

public class JunnyLand extends Throwable{
    public JunnyLand() {
        super.finalize();
    }
}

Last updated