1. 개요 코틀린의 Companion object는 static 키워드와 다르다. 1) 같은점 Companion object와 static 모두 클래스 변수, 메소드 이다. -> 즉 클래스.메소드가 가능 2) 다른점 클래스명.companion은 클래스명만으로도 사용가능 class MyClass2{ companion object{ val prop = "나는 Companion object의 속성이다." fun method() = "나는 Companion object의 메소드다." } } fun main(args: Array) { //사실은 MyClass2.맴버는 MyClass2.Companion.맴버의 축약표현이다. println(MyClass2.Companion.prop) println(MyClass2.C..
static

1. Static 변수 static 변수의 값은 함수가 종료되더라도 프로그램이 종료되지 않는 이상 메모리상에 남아있다 보통 우리가 작성하는 일반 지역변수는 스택(Stack)영역에 저장된다. 이 스택 영역의 변수들은 함수 호출시에 메모리에 할당되며 함수 종료시에 메모리에서 사라진다. 하지만 static 변수는 데이터(Data)영역에 저장된다. (+ 전역변수 또한 데이터영역에 저장된다.) 2. Static 메서드 class C1{ static int static_variable = 1; int instance_variable = 2; static void static_static(){ System.out.println(static_variable); } static void static_instance(){..