<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Kotlin Language on developwith — developer tips</title>
    <link>https://developwith.com/tags/kotlin-language/</link>
    <description>Recent content in Kotlin Language on developwith — developer tips</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <atom:link href="https://developwith.com/tags/kotlin-language/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Annotations</title>
      <link>https://developwith.com/languages/kotlin/annotations/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/languages/kotlin/annotations/</guid>
      <description>&lt;h2 id=&#34;creating-an-annotation-in-kotlin&#34;&gt;Creating an annotation in Kotlin&lt;/h2&gt;&#xA;&lt;p&gt;To create an annotation in Kotlin prefix the &lt;code&gt;class&lt;/code&gt; definition with &lt;code&gt;annotation&lt;/code&gt; and annotate the class with the desired &lt;code&gt;@Target&lt;/code&gt; and &lt;code&gt;@Retention&lt;/code&gt; scope.&lt;/p&gt;&#xA;&lt;p&gt;Example:&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-kotlin&#34; data-lang=&#34;kotlin&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nd&#34;&gt;@Target&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nc&#34;&gt;AnnotationTarget&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;FUNCTION&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nd&#34;&gt;@Retention&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nc&#34;&gt;AnnotationRetention&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;SOURCE&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;annotation&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IgnoreNull&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;&#xA;&lt;p&gt;The constructor of the annotation are the properties that can be set while annotating the desired target. For instance:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-kotlin&#34; data-lang=&#34;kotlin&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nd&#34;&gt;@Target&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nc&#34;&gt;AnnotationTarget&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;FUNCTION&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nd&#34;&gt;@Retention&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nc&#34;&gt;AnnotationRetention&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;SOURCE&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;annotation&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;IgnoreNull&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;py&#34;&gt;scope&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;String&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description>
    </item>
    <item>
      <title>Basics</title>
      <link>https://developwith.com/languages/kotlin/basics/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/languages/kotlin/basics/</guid>
      <description>&lt;p&gt;Kotlin&amp;rsquo;s programming style consists of camel case for variable and method naming. Classes and modules follow a camel case style. Kotlin allows for organization of your application into packages, classes or straight functional programming approaches. Unlike &lt;a href=&#34;https://developwith.com/languages/java/&#34;&gt;Java&lt;/a&gt; semicolons are not needed for ending lines. The typing system within Kotlin follows the approaches in Java related to object types and interfaces.&lt;/p&gt;&#xA;&lt;h2 id=&#34;comments&#34;&gt;Comments&lt;/h2&gt;&#xA;&lt;p&gt;Commenting and documenting code is an important part of coding and Kotlin uses the &lt;code&gt;/*&lt;/code&gt; start and &lt;code&gt;*\&lt;/code&gt; end as comment delineators much like C++ or &lt;a href=&#34;https://developwith.com/languages/java/&#34;&gt;Java&lt;/a&gt;. You can also add &lt;code&gt;//&lt;/code&gt; as the first characters of your line to make it into a comment which means it doesn&amp;rsquo;t have any functional value to the application. It is used to provide a way to describe what some part of the application is doing.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Condition and switches</title>
      <link>https://developwith.com/languages/kotlin/conditions-and-switches/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/languages/kotlin/conditions-and-switches/</guid>
      <description>&lt;h2 id=&#34;conditions&#34;&gt;Conditions&lt;/h2&gt;&#xA;&lt;h2 id=&#34;ternary-operator-approach&#34;&gt;Ternary operator approach&lt;/h2&gt;&#xA;&lt;p&gt;Kotlin doesn&amp;rsquo;t have a specific ternary operator like you would see in other languages, but it does allow you to use conditions within a variable assignment. This can mimic the behavior of a ternary.&lt;/p&gt;&#xA;&lt;p&gt;Kotlin ternary example:&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-kotlin&#34; data-lang=&#34;kotlin&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;val&lt;/span&gt; &lt;span class=&#34;py&#34;&gt;myValue&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;if&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cond&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;s2&#34;&gt;&amp;#34;my value&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;else&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;my other value&amp;#34;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;&#xA;&lt;p class=&#34;next&#34;&gt;&lt;strong&gt;Next:&lt;/strong&gt; &lt;a href=&#34;https://developwith.com/languages/kotlin/static-block/&#34;&gt;Static Blocks&lt;/a&gt; &lt;/p&gt;</description>
    </item>
    <item>
      <title>Static Blocks</title>
      <link>https://developwith.com/languages/kotlin/static-block/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/languages/kotlin/static-block/</guid>
      <description>&lt;p&gt;When you need an initialization of a block of code when a class in Kotlin is created, you need to create a companion block. The companion block is the equivalent to a static block in &lt;a href=&#34;https://developwith.com/languages/java/&#34;&gt;Java&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;An example of a companion block / static:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-kotlin&#34; data-lang=&#34;kotlin&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;MyClass&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;     &lt;span class=&#34;k&#34;&gt;companion&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;object&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;k&#34;&gt;init&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;For more details on companion blocks &lt;a href=&#34;https://kotlinlang.org/docs/reference/object-declarations.html#companion-objects&#34;&gt;go here&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p class=&#34;next&#34;&gt;&lt;strong&gt;Next:&lt;/strong&gt; &lt;a href=&#34;https://developwith.com/languages/kotlin/annotations/&#34;&gt;Annotations&lt;/a&gt; &lt;/p&gt;</description>
    </item>
  </channel>
</rss>
