Skip to content

Instantly share code, notes, and snippets.

View kalaiselvan369's full-sized avatar
🎯
Focusing

Kalaiselvan kalaiselvan369

🎯
Focusing
View GitHub Profile
@kalaiselvan369
kalaiselvan369 / operator_overloading.kt
Created June 12, 2023 11:18
Operator Overloading
import java.sql.Date
fun main() {
exploreRangeTo()
val scoreBoard = ScoreBoard()
scoreBoard + 6
println(scoreBoard.displayScore())
}
fun main() {
"Hi".singleQuote()
"Hello".strangeQuote()
val player = Player(name = "Sachin", team = "India")
player.hobbies(player.name)
}
fun String.singleQuote() = "'${this}'"
fun String.doubleQuote() = "\"${this}\""
package using_when
import kotlin.random.Random
fun main() {
val a = Random.nextInt(2)
when (a) {
2 -> println("even")
@kalaiselvan369
kalaiselvan369 / enums.kt
Last active June 12, 2023 11:40
Enumeration in kotlin
package enumerations
fun main() {
val east = Direction.EAST
println(east.notation)
println(east.oppositeDirection())
//println(east.opposite()) // not possible, you cannot invoke extension function declared inside class
east.westOpposite()
@kalaiselvan369
kalaiselvan369 / dealing_null.kt
Last active June 12, 2023 11:24
Dealing null values
fun main() {
val a: Int? = null
println(a)
var b: String? = "Hi"
// !! means non null assertion
for (char in b!!) {
package data_classes
data class Machine(val name: String)
enum class ShipType {
CRUISE,
WAR,
GOODS
}