Android Kaki

Build beautiful, usable products using required Components for Android.

Discover Kotlin 1.8.20. Kotlin 1.8.20 has been launched and we… | by Nav Singh 🇨🇦 | April 2023


Kotlin 1.8.20 has been launched and we’re going to discover some new options/enhancements.

  • We are going to solely embody New language function And Replace the usual library.
  • Please check with Presenter part to verify the complete particulars of this model

listing class entries operate

Why do we’d like this new performance?

  • values() – Give again Array and more often than not we convert it to a listing to work with it. Simply as in comparison with Lists, Arrays much less efficient.
  • Please verify This to study extra about efficiency points.
enum class Language(val extension: String) {
Kotlin(".KT"),
Java(".java"),
Dart(".dart")
}
// values - Returns Array
val languageValues:Array = Language.values()


// New operate entries - Returns Record
val languageEntries:Record = Language.entries

knowledge object

  • For higher readability, we have got this new function
  • It has a neat and clear toString() signify
object EmployeeObject
knowledge object EmployeeDataObject


// Output


println(EmployeeObject)


println(EmployeeDataObject)


// EmployeeObject@50040f0c


// EmployeeDataObject 💜

Sub constructors with physique in inline lessons

  • Now beginning with 1.8.20, We will use Secondary constructors with our bodies IN inline lessons 🎉
@JvmInline
worth class Worker(non-public val fullName: String) {
// Allowed since Kotlin 1.4.30:
init {
verify(fullName.isNotBlank()) {
"Full title should not be empty"
}
}
// Preview out there since Kotlin 1.8.20:
constructor(firstName: String, middleName:String, lastName: String) : this("$firstName $middleName $lastName") {
verify(lastName.isNotBlank()) {
"Final title should not be empty"
}
}
}

Self-closing interface

  • To shut the useful resource, AutoCloseable interface added frequent customary library.
  • prolonged operate use() can also be included, which executes a sure block operate on the chosen useful resource after which closes it correctly, whether or not a exception is thrown or not.

Base64 encoding and decoding

Now we now have Base64 assist in Kotlin. So no extra Java

3 sorts out there

  • Base64.Default, Base64.UrlSafe Base64.Mime
@OptIn(ExperimentalEncodingApi::class)
enjoyable base64Experimental() {
// Base64.Default
val nameBytes = "Nav".map { it.code.toByte() }.toByteArray()
val encodedValue = Base64.Default.encode(nameBytes)
// Encode worth: TmF2
println("Encoded: $encodedValue")
// Decoded worth: Nav
println("Decoded: ${String(Base64.Default.decode(encodedValue))}")
// Base64.UrlSafe
val googleIOUrlBytes = "google.io".map { it.code.toByte() }.toByteArray()
// Encode worth: Z29vZ2xlLmlv
val encodedURLSafe = Base64.UrlSafe.encode(googleIOUrlBytes)
println("Encoded UrlSafe: $encodedURLSafe")
// Decoded worth: google.io
println("Decoded UrlSafe: ${String(Base64.UrlSafe.decode(encodedURLSafe))}")
}

Assist for @Unstable Feedback in Kotlin/Native

Earlier than this 1.8.20 notice in solely out there in frequent customary library And environment friendly in JVM

  • Test This to study extra about @Unstable annotation
class Developer {
@Unstable
non-public var isAndroidDev: Boolean = false
enjoyable isAndroidDevloper(): Boolean = isAndroidDev


enjoyable setAndroidDev(isAndroidDev: Boolean) {
this.isAndroidDev = isAndroidDev
}


}

Previewing Java Composite Property References

public class Developer {
non-public String title;
non-public String coreLanguage;
public Developer(String title, String coreLanguage) {
this.title = title;
this.coreLanguage = coreLanguage;
}


public String getName() {
return title;
}


public String getCoreLanguage() {
return coreLanguage;
}
}

  • Entry properties utilizing presenter
    val developer = Developer("Nav", "Kotlin")
// references to Java artificial properties
print("Developer title is ${developer::title}")

John Wick: Chapter 4 (FREE) FULLMOVIE The Super Mario Bros Movie avatar 2 Where To Watch Creed 3 Free At Home Knock at the Cabin (2023) FullMovie Where To Watch Ant-Man 3 and the Wasp: Quantumania Cocaine Bear 2023 (FullMovie) Scream 6 Full Movie
Updated: April 10, 2023 — 6:41 pm

Leave a Reply

Your email address will not be published. Required fields are marked *

androidkaki.com © 2023 Android kaki