외우지말고 이해하라.

외우는 것 보단 이해해서 내것으로 만들어 활용하기

Another-Develop/kotlin 6

05 코틀린 - init, mapOf() , toMap()

- 액션Path,파라미터 ... - init 이란? 일종의 초기화 블록코틀린 문법 -> 객체 생성시 딱 한번 실행된다. class Rq(command:String){ val actionPath: String val paramMap: Map init { val commandBits = command.split("?", limit = 2) actionPath = commandBits[0].trim() val queryStr = if (commandBits.lastIndex == 1 && commandBits[1].isNotEmpty()) { commandBits[1].trim() } else { "" } paramMap = if (queryStr.isEmpty()) { mapOf() } else { val ..

04 코틀린 - When, downTo , .. , until

1. When when은 if나 switch를 대체할 수 있는 강력한 도구 입니다. 아래와 같이 when에 enum을 넣어 사용할 수 있습니다. (사실 이건 자바도 가능하죠) fun getMnemonic(color: Color) = when (color) { Color.RED -> "Richard" Color.ORANGE -> "Of" Color.YELLOW -> "York" Color.GREEN -> "Gave" Color.BLUE -> "Battle" Color.INDIGO -> "In" Color.VIOLET -> "Vain" } fun main(args: Array) { println(getMnemonic(Color.BLUE)) } 2.3.3 When의 인자값 When은 swith와 다르게 인자값..

03 코틀린 - MutableList

1. MutableList Kotlin의 List에는 List와 MutableList가 있습니다. List는 읽기 전용이며 MutableList는 읽기/ 쓰기가 가능합니다. Kotlin에선 List인 listOf의 사용을 권장하고 있습니다. (코드의 선명함과 안정성 때문에) 하지만 동적으로 할당되는 배열을 활용하기 위해서 MutableList를 사용해야 합니다. 참고 이유 : var num = readLine()!!.split(" ").map { it.toInt() }.toMutableList() 해당 배열을 사용하려고 하니 toMultableList 를 사용해야 num[0] 배열을 수정할 수 있었다. map{ it.toInt() } 를 사용시 변수가 리스트로 선언되고 리스트는 읽기 전용임으로 Mutab..

02 코틀린 - readLine (자료형변환) , 배열

1. readLine() 출력이 print 라면 입력을 받는 명령어 자료형 변환 ! readLine()에 변환 사용 할때 주의할 점은 Null 값이 들어 왔을때 오류 없이 처리 해주기 위해 여러 표시를 해줘야함 // val num01 = readLine().trim().toInt() -> 오류 : null 일시 trim() 에서 문제가 발생함으로 ? 를 붙여 null 일경우도 처리해준다 val num01 = readLine()?.trim()?.toInt() // ? 이랑 비슷한 기능 , !!으로 null이 아니다 라고 선언 val num02 = readLine()!!.trim().toInt() // ( A ?: B ) 오류가 없으면 A 오류가 있으면 B 실행 val num03 = (readLine() ?..

01 코틀린 - 클래스, 데이터 클래스, 타입추론 , Nullable

https://pl.kotl.in/7r-P1J0pP Kotlin Playground: Edit, Run, Share Kotlin Code Online play.kotlinlang.org 1. 클래스 fun main(){ val article1 = Article() article1.id = 1 article1.regDate = "2020-12-12 12:12:12" article1.title = "제목1" println("id : ${article1.id}, title : ${article1.title}") val article2 = Article() article2.id = 2 article2.regDate = "2020-12-12 12:12:12" article2.title = "제목2" println..