Kotlin

· JVM/Kotlin
Companion Object 클래스 안에 존재하는 SingleTon Object Comapnion이라는 이름을 가진 static Singletone companion keyword는 그냥 Companion이란 이름을 갖는 클래스 객체를 가리키는 shortcut 역할을 할 뿐. companion object 내에 생성된 변수, 메소드는 부모 클래스의 static 맴버가된다. class - companion object는 1:1 매칭 (오로지 1개씩 선언 가능) class ToBeCalled { companion object Test { val someInteger: Int = 10 fun callMe() = println("You are calling me :)") } } fun main(args: Ar..
· JVM/Kotlin
[Elvis Operator] val number : Int = number1 ?: 10 number1이 null -> 10 대입 not null -> number1 대입 [!!] Not Null 임을 개발자가 보장하는것. 협업시 다른사람이 임의로 !!처리한 변수를 null 값을 삽입할 시... 에러가 발생하기 쉽다 애초에 어떤 식에 '!!'키워드를 붙일 수 있다는 것 자체가 nullable Varaible 인 경우일 때 의도치 않게 null값을 갖는 경우 nullPointerException 발생 위험이 생기기 때문에 연산자를 남발하는 것은 좋지 못하다. [lateinit] Non-null Property 가 값이 저장되지 않은 상태를 컴파일러가 '인정'하도록 하는 키워드. 키워드 단어 뜻 그대로 늦은..
M_Falcon
'Kotlin' 태그의 글 목록 (4 Page)