1. 개요


2. 역사

2011년 7월 JetBrains가 발표한 JVM 기반 프로그래밍 언어이다. 그들은 스칼라의 컴파일 시간에 불만을 가졌기에 자바만큼 빠른 컴파일을 추구했다. (JetBrains는 IntelliJ IDEA, PyCharm 등을 개발한 회사다)

2012년 2월에는 Apache 2.0 라이선스 기반으로 공개했다.

현재는 구글의 안드로이드 공식 언어 중 하나로 안드로이드 앱 개발자에게 선호되는 언어이다. 요즘 안드로이드 공식 문서의 예제 코드는 Kotlin으로 짜여져 있다고 한다.


3. 특징

  • 문법이 간결하다.
  • 세미콜론은 옵션이다. 다시 말해 필요가 없고, 있어도 오류가 나진 않는다.
  • 자바와 달리 == 가 equals()이다.
  • 모든 함수가 리턴값이 있다.
  • 기타 등등..
     
  • 장점 : 코드량이 줄어든다. 생산성
  • 단점 : 바이트코드량이 증가, 컴파일 시간 증가

4. 도구

IntelliJ IDEA, 안드로이드 스튜디오에서 사용 가능하고 이클립스에서도 kotlin 플러그인을 설치하여 사용 가능하다.


5. 테스트 코드

fun max(a: Int, b: Int): Int  {
    return if ( a > b ) a else b
}

fun min(a: Int, b: Int): Int  {
    return if ( a < b ) a else b
}

fun main(args : Array) {
    println("Hello, Kotlin!")
    println(max(100,200))
    println(max(200,300))
    println(min(300,400))
}

[ 결과 ]

Hello, Kotlin!
200
300
300

6. 기타

6.1. build.gradle 예제

buildscript {
    ext {
        kotlinVersion = "1.1.2-3"
    }

    repositories {
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
        classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion"
    }
}

apply plugin: "kotlin"
apply plugin: "kotlin-spring"

repositories {
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
    compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
    compile "org.springframework:spring-core:$springVersion"
    compile "org.springframework:spring-web:$springVersion"
    compile "org.springframework:spring-context:$springVersion"
    compile "org.springframework:spring-jdbc:$springVersion"
    compile "com.fasterxml.jackson.dataformat:jackson-dataformat-csv:2.7.0"

    compile "org.hibernate:hibernate-core:$hibernateVersion"
    compile "org.slf4j:slf4j-api:$slf4jVersion"

    testCompile "junit:junit:$junitVersion"
}