title: Kotlin: Difference between constant in companion object and top level
body: <p>The general pattern to create constants in Kotlin seems to be using companion objects. However, I can also define a constant at the file level. Why is that not so popular? Am I missing something?</p>
  
  <p>With companion object:</p>
  
  <pre><code>class Example {
      companion object {
          const val CONSTANT = "something"
  }
  </code></pre>
  
  <p>On top level:</p>
  
  <pre><code>const val CONSTANT = "something"
  
  class Example {
  }
  </code></pre>