joshua-r2
10/24/2017 - 3:00 PM

Class Constructors

Primary Constructor cannot have any code and has no annotations or visibility modifiers. Secondary constructors are typically not used in Kotlin due to ability to set default values. The primary use case for secondary constructors is Java interoptability

//Primary Constructor/ClassDefinition
class Doggo(val type: String){

  //Code to execute on initialization of primary constructor
  init{
    //.....
  }

  //Secondary Constructor
  constructor(val Type: String, val borkSound: String){
  //Do Stuff
  
  }
  
  //Delegation to another constructor using this (will invoke init code)
  constructor(type:String, val borkSound: String, val weight: Long): this(type){
    
  }



}