<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Adil Khan on Medium]]></title>
        <description><![CDATA[Stories by Adil Khan on Medium]]></description>
        <link>https://medium.com/@adil9dtechnologies?source=rss-1c9fdf8db9da------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*e-8qL_lKKaBsflta.jpg</url>
            <title>Stories by Adil Khan on Medium</title>
            <link>https://medium.com/@adil9dtechnologies?source=rss-1c9fdf8db9da------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 11:36:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adil9dtechnologies/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Kotlin examples]]></title>
            <link>https://medium.com/@adil9dtechnologies/kotlin-examples-f43cd2fc2e00?source=rss-1c9fdf8db9da------2</link>
            <guid isPermaLink="false">https://medium.com/p/f43cd2fc2e00</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin-beginners]]></category>
            <dc:creator><![CDATA[Adil Khan]]></dc:creator>
            <pubDate>Thu, 06 Jan 2022 05:22:12 GMT</pubDate>
            <atom:updated>2022-01-06T05:22:12.795Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>1. Variable declaration</strong></p><blockquote><em>var name = “Igor” // Inferred type is String</em></blockquote><blockquote><em>name = “Marcin”</em></blockquote><blockquote><em>var name = “Igor”</em></blockquote><blockquote><em>name = 2 // Error, because name type is String</em></blockquote><blockquote><em>val name = “Marcin”</em></blockquote><blockquote><em>println(“My name is $name”) // Prints: My name is Marcin</em></blockquote><blockquote><em>val name = “Igor”</em></blockquote><blockquote><em>println(“My name is ${name.toUpperCase()}”) // Prints: My name is IGOR</em></blockquote><p><strong>1.1 Nullable values:</strong></p><blockquote><em>var a: String = “abc”</em></blockquote><blockquote><em>a = null // compilation error</em></blockquote><blockquote><em>var b: String? = “abc” b = null // It is correct</em></blockquote><p><strong>1.2 Ranges:</strong></p><blockquote><em>for (i in 1..10) {</em></blockquote><blockquote><em>print(i)</em></blockquote><blockquote><em>} // 12345678910</em></blockquote><p><strong>1.3 Pair of values:</strong></p><blockquote><em>val capitol = “England” to “London”</em></blockquote><blockquote><em>println(capitol.first) // Prints: England</em></blockquote><blockquote><em>println(capitol.second) // Prints: London</em></blockquote><p><strong>1.4 Separate variables using destructive declarations:</strong></p><blockquote><em>val (country, city) = capitol</em></blockquote><blockquote><em>println(country) // Prints: England</em></blockquote><blockquote><em>println(city) // Prints: London</em></blockquote><p><strong>1.5 A list of pairs:</strong></p><blockquote><em>val capitols = listOf(“England” to “London”, “Poland” to “Warsaw”)</em></blockquote><blockquote><em>for ((country, city) in capitols) {</em></blockquote><blockquote><em>println(“Capitol of $country is $city”)</em></blockquote><blockquote><em>}</em></blockquote><blockquote><em>// Prints: // Capitol of England is London</em></blockquote><blockquote><em>// Capitol of Poland is Warsaw</em></blockquote><p><strong>1.6 ForEach function:</strong></p><blockquote><em>val capitols = listOf(“England” to “London”, “Poland” to “Warsaw”)</em></blockquote><blockquote><em>capitols.forEach { (country, city) -&gt;</em></blockquote><blockquote><em>println(“Capitol of $country is $city”)</em></blockquote><blockquote><em>}</em></blockquote><p><strong>1.7 Mutable and Immutable collections</strong></p><blockquote><em>val list = listOf(1, 2, 3, 4, 5, 6) // Inferred type is List</em></blockquote><blockquote><em>val mutableList = mutableListOf(1, 2, 3, 4, 5, 6) // Inferred type is MutableList</em></blockquote><p><strong>1.8 Lambda expressions</strong></p><blockquote><em>view.setOnClickListener {</em></blockquote><blockquote><em>println(“Click”)</em></blockquote><blockquote><em>}</em></blockquote><p><strong>1.9 Stream processing on lists (stdlib):</strong></p><blockquote><em>val text = capitols.map { (country, _) -&gt; country.toUpperCase() } .onEach {</em></blockquote><blockquote><em>println(it)</em></blockquote><blockquote><em>} .filter {</em></blockquote><blockquote><em>it.startsWith(“P”)</em></blockquote><blockquote><em>} .joinToString (prefix = “Countries prefix P:”) // Prints: ENGLAND POLAND</em></blockquote><blockquote><em>println(text) // Prints: Countries prefix P: POLAND</em></blockquote><blockquote><em>.joinToString (prefix = “Countries prefix P:”)</em></blockquote><p><strong>1.10 Android Marshmallow or newer (own lambdas)</strong></p><blockquote><em>inline fun supportsMarshmallow(code: () -&gt; Unit) {</em></blockquote><blockquote><em>if(Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) code()</em></blockquote><blockquote><em>}</em></blockquote><blockquote><em>//usage</em></blockquote><blockquote><em>supportsMarshmallow {</em></blockquote><blockquote><em>println(“This code will only run on Android Nougat and newer”)</em></blockquote><blockquote><em>}</em></blockquote><p><strong>1.11 Main thread using the doAsync function:</strong></p><blockquote><em>doAsync {</em></blockquote><blockquote><em>var result = runLongTask() // runs on background thread</em></blockquote><blockquote><em>uiThread {</em></blockquote><blockquote><em>toast(result) // run on main thread</em></blockquote><blockquote><em>}</em></blockquote><blockquote><em>}</em></blockquote><p><strong>1.12 Smart casts</strong></p><blockquote><em>if (x is String) {</em></blockquote><blockquote><em>print(x.length) // x is automatically casted to String</em></blockquote><blockquote><em>}</em></blockquote><blockquote><em>x.length //error, x is not casted to a String outside if block</em></blockquote><blockquote><em>if (x !is String) return</em></blockquote><blockquote><em>x.length // x is automatically casted to String</em></blockquote><p><strong>1.13 Function that returns</strong></p><blockquote><em>fun sum(a: Int, b: Int) = a + b</em></blockquote><blockquote><em>println (sum(2 + 4)) // Prints: 6</em></blockquote><p><strong>1.14 Function argument and call</strong></p><blockquote><em>fun printMessage(product: String, amount: Int = 0, name: String = “Anonymous”) {</em></blockquote><blockquote><em>println(“$name has $amount $product”)</em></blockquote><blockquote><em>}</em></blockquote><blockquote><em>printMessage(“oranges”) // Prints: Anonymous has 0 oranges</em></blockquote><blockquote><em>printMessage(“oranges”, 10) // Prints: Anonymous has 10 oranges</em></blockquote><blockquote><em>printMessage(“oranges”, 10, “Johny”) // Prints: Johny has 10 oranges</em></blockquote><blockquote><em>//named argument syntax</em></blockquote><blockquote><em>printMessage(“oranges”, name = “Bill”)</em></blockquote><p><strong>1.15 Data classes</strong></p><blockquote><em>data class Ball(var size:Int, val color:String)</em></blockquote><blockquote><em>val ball = Ball(12, “Red”)</em></blockquote><blockquote><em>println(ball) // Prints: Ball(size=12, color=Red)</em></blockquote><p><strong>1.16 Custom copy of the class:</strong></p><blockquote><em>val ball = Ball(12, “Red”)</em></blockquote><blockquote><em>println(ball) // prints: Ball(size=12, color=Red)</em></blockquote><blockquote><em>val smallBall = ball.copy(size = 3)</em></blockquote><blockquote><em>println(smallBall) // prints: Ball(size=3, color=Red)</em></blockquote><blockquote><em>smallBall.size++ println(smallBall) // prints: Ball(size=4, color=Red)</em></blockquote><blockquote><em>println(ball) // prints: Ball(size=12, color=Red)</em></blockquote><p><strong>1.17 Extensions Function</strong></p><blockquote><strong><em>//</em></strong><em>(an image loading library for Android)</em></blockquote><blockquote><em>fun ImageView.loadUrl(url: String) {</em></blockquote><blockquote><em>Picasso.with(context).load(url).into(this)</em></blockquote><blockquote><em>}</em></blockquote><blockquote><em>\\usage</em></blockquote><blockquote><em>imageView.loadUrl(“www.test.com\\image1.png&quot;)</em></blockquote><blockquote><em>//toast</em></blockquote><blockquote><em>fun Context.toast(text:String) {</em></blockquote><blockquote><em>Toast.makeText(this, text, Toast.LENGTH_SHORT).show()</em></blockquote><blockquote><em>}</em></blockquote><blockquote><em>//usage (inside Activity class)</em></blockquote><blockquote><em>toast(“Hello”)</em></blockquote><p><strong>1.18 Interfaces</strong></p><blockquote><em>interface BasicData {</em></blockquote><blockquote><em>val email:String</em></blockquote><blockquote><em>val name:String get() = email.substringBefore(“@”)</em></blockquote><blockquote><em>}</em></blockquote><p><strong>1.19 Delegates</strong></p><blockquote><em>val retrofit by lazy {</em></blockquote><blockquote><em>Retrofit.Builder()</em></blockquote><blockquote><em>.baseUrl(“https://www.github.com&quot;)</em></blockquote><blockquote><em>.addConverterFactory(MoshiConverterFactory.create())</em></blockquote><blockquote><em>.build()</em></blockquote><blockquote><em>}</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f43cd2fc2e00" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>