Statically typed programming language
for the JVM, Android and the browser
100% interoperable with Java™
PaymentRobot payment = new PaymentRobot();
ResultRobot result = payment
.amount(42_00)
.recipient("foo@bar.com")
.send();
result.isSuccess();
val payment = PaymentRobot()
val result = payment
.amount(4200)
.recipient("foo@bar.com")
.send()
result.isSuccess()
val result = payment {
amount(4200)
recipient("foo@bar.com")
}.send()
result.isSuccess()
payment {
amount(4200)
recipient("foo@bar.com")
}.send {
isSuccess()
}
payment {
amount(4200)
recipient("foo@bar.com")
} send {
isSuccess()
}
payment {
amount(4200)
recipient("foo@bar.com")
send()
}
birthday {
date(1970, 1, 1)
next()
}
ssn {
value("123-56-7890")
next()
}
result {
isSuccess()
}
public String foo() {

...

}
// null or non-null?

String f = foo();
@NonNull
public String foo() {

...

}
// non-null

String f = foo();
// nullable

fun nullable(): String? {

...

}



// non-null

fun nonNull(): String {

...

}
// ok

val foo: String? = "foo"



// compile error

val bar: String = null
String foo = "foo";

String bar = "foo";

// isEquals: true
boolean isEquals = foo.equals(bar);
String foo = "foo";

String bar = "foo";



// isEquals: false
boolean isEquals = foo == bar;
val foo = "foo"

val bar = "bar"



// isEquals: true
val isEquals = foo == bar
// MyFunctions.kt



package com.sample.package



fun foo() { }
// OtherFunctions.kt

package com.sample.package.others

// import function foo()

import com.sample.package.foo



fun baz() {

foo()

}
public class MainActivity extends AppCompatActivity {



Button btnCalligraphy;



@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);



btnCalligraphy = (Button) findViewById(R.id.btn_calligraphy);



btnCalligraphy.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

// Do something

}

});



}

}
class MainActivity : AppCompatActivity() {



override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)



btn_calligraphy.setOnClickListener {

// Do something

}

}

}
view.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(
v.getContext().getApplicationContext(),

"Hello", Toast.LENGTH_SHORT).show();

}

});
view.setOnClickListener({ v ->



Toast.makeText(v.context.applicationContext,

"Hello", Toast.LENGTH_SHORT).show()



})
view.setOnClickListener { v ->



Toast.makeText(v.context.applicationContext,

"Hello", Toast.LENGTH_SHORT).show()



}
view.setOnClickListener {



Toast.makeText(it.context.applicationContext,

"Hello", Toast.LENGTH_SHORT).show()



}
val people : List<String> = ..


people.filter { it.startsWith('S') }

.filter { it.length < 10 }

.onEach { it.toUpperCase() }

.forEach { println(it) }
val people : List<String> = ..


people.filter { it.startsWith('S') }

.filter { it.length < 10 }

.onEach(String::toUpperCase)

.forEach(::println)
val people : List<String> = ..


people.stream()

.filter { it.startsWith('S') }

.filter { it.length < 10 }

.map(String::toUpperCase)

.forEach(::println)
var foo : String = "Foo"

foo = "FOO"



val bar : String = "Bar"

bar = "BAR"
var foo : String = "Foo"

foo = "FOO"



val bar : String = "Bar"

bar = "BAR"
Compile Error (val cannot be reassigned)
val mutableList : MutableList<String>
= mutableListOf(“foo", "bar", "baz")

mutableList.add("fizz")



val immutableList : List<String>
= listOf("foo", "bar", "baz")

immutableList.add("fizz")
val mutableList : MutableList<String>
= mutableListOf("foo", "bar", "baz")

mutableList.add("fizz")



val immutableList : List<String>
= listOf("foo", "bar", "baz")

immutableList.add("fizz")
Compile Error (val cannot be reassigned)
val emptyStringList = listOf<String>()



val cities = listOf("Seoul", "Busan")



val mutableCities = mutableListOf("Seoul, Busan")
val emptyStringSet = setOf<String>()



val cities = setOf("Seoul", "Busan")



val mutableCities = mutableSetOf("Seoul, Busan")
val pair : Pair<String, String> = Pair("Seoul", "서울")
val pair : Pair<String, String> = "Seoul" to "서울"
public class Person {



String name;



String address;



Person(String name, String address) {

this.name = name;

this.address = address;

}



public String getAddress() {

return address;

}



public void setAddress(String address) {

this.address = address;

}

}
public class Person {



String name;



String address;



Person(String name, String address) {

this.name = name;

this.address = address;

}



public String getAddress() {

return address;

}



public void setAddress(String address) {

this.address = address;

}



@Override

public boolean equals(Object o) {

if (this == o) {

return true;

}

if (o == null || getClass() != o.getClass()) {

return false;

}



Person person = (Person) o;



if (!name.equals(person.name)) {

return false;

}

return address != null ? address.equals(person.address) : person.address == null;



}



@Override

public int hashCode() {

int result = name.hashCode();

result = 31 * result + (address != null ? address.hashCode() : 0);

return result;

}



@Override

data class Person(val name: String, val address: String)
Toast.makeText(applicationContext,
"Hello, Kotlin!", Toast.LENGTH_SHORT).show()
// Define an extension function on Context
fun Context.toast(message: String) {

Toast.makeText(this.applicationContext,
message, Toast.LENGTH_SHORT).show()

}
// available in class Context and its descendants
toast("Hello, Kotlin!")
Happy Kotlin!

레진코믹스가 코틀린으로 간 까닭은?

  • 4.
    Statically typed programminglanguage for the JVM, Android and the browser 100% interoperable with Java™
  • 12.
    PaymentRobot payment =new PaymentRobot(); ResultRobot result = payment .amount(42_00) .recipient("foo@bar.com") .send(); result.isSuccess();
  • 13.
    val payment =PaymentRobot() val result = payment .amount(4200) .recipient("foo@bar.com") .send() result.isSuccess()
  • 14.
    val result =payment { amount(4200) recipient("foo@bar.com") }.send() result.isSuccess()
  • 15.
  • 16.
  • 17.
    payment { amount(4200) recipient("foo@bar.com") send() } birthday { date(1970,1, 1) next() } ssn { value("123-56-7890") next() } result { isSuccess() }
  • 24.
    public String foo(){
 ...
 } // null or non-null?
 String f = foo();
  • 25.
    @NonNull public String foo(){
 ...
 } // non-null
 String f = foo();
  • 26.
    // nullable
 fun nullable():String? {
 ...
 }
 
 // non-null
 fun nonNull(): String {
 ...
 }
  • 27.
    // ok
 val foo:String? = "foo"
 
 // compile error
 val bar: String = null
  • 28.
    String foo ="foo";
 String bar = "foo";
 // isEquals: true boolean isEquals = foo.equals(bar);
  • 29.
    String foo ="foo";
 String bar = "foo";
 
 // isEquals: false boolean isEquals = foo == bar;
  • 30.
    val foo ="foo"
 val bar = "bar"
 
 // isEquals: true val isEquals = foo == bar
  • 32.
  • 33.
    // OtherFunctions.kt
 package com.sample.package.others
 //import function foo()
 import com.sample.package.foo
 
 fun baz() {
 foo()
 }
  • 36.
    public class MainActivityextends AppCompatActivity {
 
 Button btnCalligraphy;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 btnCalligraphy = (Button) findViewById(R.id.btn_calligraphy);
 
 btnCalligraphy.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View view) {
 // Do something
 }
 });
 
 }
 }
  • 37.
    class MainActivity :AppCompatActivity() {
 
 override fun onCreate(savedInstanceState: Bundle?) {
 super.onCreate(savedInstanceState)
 setContentView(R.layout.activity_main)
 
 btn_calligraphy.setOnClickListener {
 // Do something
 }
 }
 }
  • 38.
    view.setOnClickListener(new View.OnClickListener() {
 @Override
 publicvoid onClick(View v) {
 Toast.makeText( v.getContext().getApplicationContext(),
 "Hello", Toast.LENGTH_SHORT).show();
 }
 });
  • 39.
  • 40.
    view.setOnClickListener { v->
 
 Toast.makeText(v.context.applicationContext,
 "Hello", Toast.LENGTH_SHORT).show()
 
 }
  • 41.
  • 42.
    val people :List<String> = .. 
 people.filter { it.startsWith('S') }
 .filter { it.length < 10 }
 .onEach { it.toUpperCase() }
 .forEach { println(it) }
  • 43.
    val people :List<String> = .. 
 people.filter { it.startsWith('S') }
 .filter { it.length < 10 }
 .onEach(String::toUpperCase)
 .forEach(::println)
  • 44.
    val people :List<String> = .. 
 people.stream()
 .filter { it.startsWith('S') }
 .filter { it.length < 10 }
 .map(String::toUpperCase)
 .forEach(::println)
  • 45.
    var foo :String = "Foo"
 foo = "FOO"
 
 val bar : String = "Bar"
 bar = "BAR"
  • 46.
    var foo :String = "Foo"
 foo = "FOO"
 
 val bar : String = "Bar"
 bar = "BAR" Compile Error (val cannot be reassigned)
  • 47.
    val mutableList :MutableList<String> = mutableListOf(“foo", "bar", "baz")
 mutableList.add("fizz")
 
 val immutableList : List<String> = listOf("foo", "bar", "baz")
 immutableList.add("fizz")
  • 48.
    val mutableList :MutableList<String> = mutableListOf("foo", "bar", "baz")
 mutableList.add("fizz")
 
 val immutableList : List<String> = listOf("foo", "bar", "baz")
 immutableList.add("fizz") Compile Error (val cannot be reassigned)
  • 51.
    val emptyStringList =listOf<String>()
 
 val cities = listOf("Seoul", "Busan")
 
 val mutableCities = mutableListOf("Seoul, Busan")
  • 52.
    val emptyStringSet =setOf<String>()
 
 val cities = setOf("Seoul", "Busan")
 
 val mutableCities = mutableSetOf("Seoul, Busan")
  • 53.
    val pair :Pair<String, String> = Pair("Seoul", "서울")
  • 54.
    val pair :Pair<String, String> = "Seoul" to "서울"
  • 55.
    public class Person{
 
 String name;
 
 String address;
 
 Person(String name, String address) {
 this.name = name;
 this.address = address;
 }
 
 public String getAddress() {
 return address;
 }
 
 public void setAddress(String address) {
 this.address = address;
 }
 }
  • 56.
    public class Person{
 
 String name;
 
 String address;
 
 Person(String name, String address) {
 this.name = name;
 this.address = address;
 }
 
 public String getAddress() {
 return address;
 }
 
 public void setAddress(String address) {
 this.address = address;
 }
 
 @Override
 public boolean equals(Object o) {
 if (this == o) {
 return true;
 }
 if (o == null || getClass() != o.getClass()) {
 return false;
 }
 
 Person person = (Person) o;
 
 if (!name.equals(person.name)) {
 return false;
 }
 return address != null ? address.equals(person.address) : person.address == null;
 
 }
 
 @Override
 public int hashCode() {
 int result = name.hashCode();
 result = 31 * result + (address != null ? address.hashCode() : 0);
 return result;
 }
 
 @Override

  • 57.
    data class Person(valname: String, val address: String)
  • 58.
  • 59.
    // Define anextension function on Context fun Context.toast(message: String) {
 Toast.makeText(this.applicationContext, message, Toast.LENGTH_SHORT).show()
 } // available in class Context and its descendants toast("Hello, Kotlin!")
  • 64.