dotcomlmka.blogg.se

With kotlin
With kotlin








with kotlin

In this Kotlin Tutorial, we learned what a Kotlin with function is, and how to use this to create a scope (with-block) for an object (receiver) and access its members and functions. Now, let us return length of the receiver object str from the with-block. In the following example, we will return lowercase value of the String from with-block.

with kotlin

Just place the return value as the last statement in the with-block. This programming language is statically typed, which means that variables, functions, and expressions use predefined sets of types that can be checked on compile time. Output Hello World! Return Value from With-Block Kotlin is a programming language, developed by JetBrains, that runs on Java Virtual Machines (JVMs) and that can also be compiled to JavaScript. To access receiver itself in the with-block, use this keyword. Inside the with-block, we have accessed length property and called uppercase() function of the receiver object str, with actually referencing the object str again like str.length or str.uppercase(). In the following example, we will pass a String value for receiver object to with() and access the properties and functions of the String in the block.










With kotlin