Please enable JavaScript.
Coggle requires JavaScript to display documents.
Kotlin - Coggle Diagram
Kotlin
Control Flow
-
for loop
-
-
for ((i,e) in items.withIndex()) println("the index is $i and the element is $e")
-
-
-
-
-
-
Null saftey
-
-
-
-
-
let function Let function executes the lamda function specified only when the reference is non-nullable as shown below.
-
FilterNotNull is used to filter null values.
var array2: Array<Any?> = arrayOf("1", "2", "3", null)
var newArray = array2.filterNotNull()
Class
By default, classes are non inheritable
-
-
-
-
-
Using open keyword, one can inherit a class
String
-
accessing characters
var str = "Hello, Kotlin"
print(str[0]) //prints H
-
String Templates
Instead of concatenating an expression in a string, Strings can contain expressions/statements following a dollar symbol as shown below.
Referential Equality: Checks if the pointers for two objects are the same. === operator is used.
Structural Equality : Checks if the contents of both the objects are equal. == is used.
-
Array
Array declaration val countries = arrayOf("India","USA","China","Australia","Sri Lanka")
we can store different type of items in array .
val myArray = arrayOf("Hi",1,1L,1.2,false)
-
-
-
appending element var array1 = arrayOf(1,2,3,4)
array1 = array1.plus(5)
-
-
Data Class
-
-
-
-
if visibilty modifier is imposed , it cant be accessed
-
Visibility Modifier Link Title
A Public Modifier is the default modifier in Kotlin. Just like the Java public modifier, it means that the declaration is visible everywhere.
The setters of properties in Kotlin can have a separate modifier from the property. The getters can’t have a visibility modifier defined. They use the same modifier as that of the property.
CANNOT be set on top-level declarations.
Declarations that are protected in a class, can be accessed only in their subclasses.
-
Interface
-
If interface is not used anywhere else, it becomes useless
-
if two interfaces are having same method name , then we use super keyword.
for ex, super<DemoClass>.demoMethod
Inheriatance
-
-
if child class has primary constructor, ithen it has to refer to primary constructor of parent class
If child class does not have constructor , then it has to refer primary constructor of parent class using secondary constructor using super keyword
Enum
-
println(Months.January); //prints JANUARY println(Months.January.name) ; //prints January println(Months.valueOf("March")) //prints MARCH
enum class Months { January, February, March; override fun toString(): String { return super.toString().toUpperCase() } }
-
-
-
-
-
-
-
-