title: Right way to initialise SharedPreference in Kotlin
body: <p>I am very new to Kotlin. Previously, I used to declare a SharedPreference in an activity as such:</p>
  
  <pre><code>class MainActivity extends AppCompatActivity {
      SharedPreferences main;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          main = getSharedPreferences("main", MODE_PRIVATE);
      }
  }
  </code></pre>
  
  <p>This allowed me to use the <code>main</code> instance throughout the class. I would like to achieve a similar functionality. I am currently using <code>lateinit var</code> as such:</p>
  
  <pre><code>
  class MainActivityKotlin : AppCompatActivity() {
      lateinit var main : SharedPreferences
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          main = getSharedPreferences("main", Context.MODE_PRIVATE)
      }
  }
  </code></pre>
  
  <p>But I am not sure if this is the right way of doing it.
  Also this is a <code>var</code>. As far as I understand, a <code>val</code> is usually recommended where the instance will not change (like in this case, <code>main</code> will not change once initialised). So is this approach correct?</p>