import static


static으로 선언된 필드나 메서드는 클래스 이름을 통해 접근이 가능하지만 

클래스 이름을 적어 호출하기 싫으면 위에 static을 통째로 import 한 뒤 다이렉트로 호출해서 사용할 수 있다.


import static java.lang.Math.PI;

import static java.lang.Integer.parseInt;

public class ImportStatic {
public static void main(String[] args) {
// 1. 일반적인 static 변수/메서드 호출 방법
// static으로 선언된 필드나 메서드는 클래스 이름을 통해 다음과 같이 접근이 가능하다.
System.out.println(Math.PI);
// static으로 선언된 필드는 위와 같이 다이렉트로 사용이 가능하다.
System.out.println(Integer.parseInt("123")); 
// 2. import static 
// 클래스 이름을 적어 호출하기 싫으면 위에 static을 통째로 import 한 뒤 다이렉트로 호출해서 사용할 수 있다.
System.out.println(PI);
System.out.println(Integer.parseInt("123")); 
}
}


Posted by netyhobby
,