List the Features of Kotlin Programming Language

Kotlin Features:

1. Expressiveness: With Kotlin, it’s much easier to avoid boilerplate because the most common patterns are covered by default in the language. For instance, in Java, if we want to create a data class, we’ll need to write this code:

public class Artist {
private long id;
private String name;
private String url;
private String mbid;
public long getId() 
{
  return id;
}
public void setId(long id) {
   this.id = id;
 }
public String getName() {
return name;
 }
public void setName(String name) {
 this.name = name;
 }
public String getUrl() {
 return url;
 }
public void setUrl(String url) {
 this.url = url;
 }
public String getMbid() {
return mbid;
}
public void setMbid(String mbid) {
 this.mbid = mbid;
}
@Override public String toString() {
return "Artist{" +
"id=" + id +
", name='" + name + '\'' +
", url='" + url + '\'' +
", mbid='" + mbid + '\'' +
'}';
}
}

2. Null Safety: When we use Java, a big amount of our code is defensive. We need to check once and another whether something is null before using it if we don’t want to find an unexpected NullPointerException. Kotlin, like many other modern languages, is null safe because the type explicitly defines whether an object can be null by using the safe call operator (written ?).
We can do things like this:

var notNullArtist: Artist = null
var artist: Artist? = null
artist.print()
artist?.print()
if (artist != null) {
artist.print()
 }
artist!!.print()
val name = artist?.name ?: "empty"

3. Extension Functions: You can add new functions to any class. It’s a much more readable substitute to the usual utility classes we all have in our projects. You could, for instance, add a new method to fragments to show a toast:

4. Functional Support: What if, instead of having to declare an anonymous class every time we need to implement a click listener, we could just define what we want to do? We can indeed. This is what we get thanks to lambdas:

view.setOnClickListener { toast("Hello world!") }