This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
// lambda | |
println(apply(5, { it * it })) | |
// anonymous function | |
println(apply(5, fun(n: Int): Int { return n * n})) | |
} | |
fun apply(num: Int, op: (Int) -> Int): Int { | |
return op(num) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Address(var street: String?, var City: String) | |
class User(var name: String, var address: Address?) | |
fun main(args: Array<String>) { | |
var address = Address(null, "Colombo") | |
var user = User("Dharmapala", address) | |
println(user.address?.street?.toUpperCase()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun String.toSentenceCase(): String = this.substring(0, 1).toUpperCase().plus(this.substring(1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
println(2 powerTo 4) | |
} | |
infix fun Int.powerTo(to: Int): Double { | |
return Math.pow(this.toDouble(), to.toDouble()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
println("this is cool".toSentenceCase()) | |
} | |
fun String.toSentenceCase(): String { | |
return this.substring(0, 1).toUpperCase().plus(this.substring(1)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File | |
import com.ruwanka.io.File as MyFile | |
fun main(args: Array<String>) { | |
var myFile: MyFile = MyFile() | |
var javaFile: File = File("test.txt"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ruwanka.io; | |
public class Program { | |
public static void main(String[] args) { | |
File myFile = new File(); | |
java.io.File javaFile = new java.io.File("test.txt"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ruwanka.io; | |
public class File { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Student(var name: String, var age: Int, val gender: String) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ruwanka.realmdbinspect; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import com.ruwanka.realmdbinspect.model.Address; | |
import com.ruwanka.realmdbinspect.model.Person; | |
import io.realm.Realm; |