In the Java world, we used to initialize fields of the class in the constructor, as shown in this code:
class Student{
int roll_number;
String name;
Student(int roll_number,String name){
this.roll_number =roll_number;
this.name = name;
}
}
So, if the argument's name was similar to that of the property (which was usually the case for making the code more readable), we needed to use this keyword. In this recipe, we will see how to implement the same thing in Kotlin (obviously with much less code).