static block 이란?
클래스 변수를 초기화시키는 용도의 블럭으로 클래스 변수가 로드될 때 바로 실행된다.
public class CryptoCurrency {
public static Map<String, String> map = new HashMap<>();
static {
map.put("BTC", "Bitcoin");
map.put("ETH", "Ethereum");
map.put("ADA", "ADA");
map.put("POT", "Polkadot");
}
}
프로세스
- 클래스 로딩
- 클래스 변수 메모리 생성
- 선언된 static 블럭 순서대로 실행
https://www.geeksforgeeks.org/static-blocks-in-java/
Static Blocks in Java - GeeksforGeeks
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
www.geeksforgeeks.org
'Language > Java' 카테고리의 다른 글
자바에서의 Hash (0) | 2023.04.09 |
---|---|
Thread의 생성과 실행 (0) | 2022.07.19 |
Stream의 여러 예제들 (0) | 2022.07.19 |