class DemoScope {
}
fun customPrint(s: String) {
print(s.uppercase())
}
fun printNonNull(str:String?)
{
println("Print $str")
str?.let{
print("*")
customPrint(it)
println()
}
}
fun printIfBothNonNull(strOne:String?,strTwo:String?)
{
strOne?.let{ firstString->
strTwo?.let{
secondString -> customPrint("$firstString : $secondString")
println()
}
}
}
fun getNullableLength(ns:String?)
{
println("for $ns")
ns?.run{
println("\t is empty?"+isEmpty())
println("\tlength = $length")
length
}
}
class Configuration(var host:String,var port:Int)
class Cat()
{
var name="Mimi"
var age=12
var about="aaaa"
}
data class Person1(var name:String,var age:Int,var about:String)
{
constructor():this("",0,"")
}
fun writeCteationLog(p:Person1)
{
println("A new person ${p.name} was created.")
}
fun main()
{
val jake = Person1("Jake",45,"Android").also {
writeCteationLog(it)
}
// val jake = Cat()
// val stringDescription = jake.apply {
// name = "Jake"
// age = 30
// about = "Android developer"
//
// }.toString()
// println(stringDescription)
// val configuration = Configuration(host="127.0.0.1", port = 9000)
// with(configuration)
// {
// println("$host:$port")
// }
// getNullableLength(null)
// getNullableLength("")
// getNullableLength("some string with Kotlin")
// printIfBothNonNull("First","Second")
// printNonNull(null)
// println("$empty")
// val empty = "test".let{
// customPrint(it)
// it.isEmpty()
// }
}