title: Kotlin object vs companion-object vs package scoped methods
body: <p>I have written this methods in Kotlin and analysed the bytecode:</p>
  
  <h1>Situation 1</h1>
  
  <pre><code>class A {
      object b {
          fun doSomething() {}
      }
  }
  </code></pre>
  
  <h1>Situation 2</h1>
  
  <pre><code>class A {
      companion object b {
          fun doSomething() {}
      }
  }
  </code></pre>
  
  <h1>Situation 3</h1>
  
  <pre><code>fun doSomething() {}
  </code></pre>
  
  <p>Bytecode Result</p>
  
  <ul>
  <li>Situation 1: class <code>Test$asb</code>, <code>public final doSomething()I</code></li>
  <li>Situation 2: class <code>Test$Companion</code>, <code>public final doSomething()I</code></li>
  <li>Situation 3: class <code>TestKt</code>, <code>public final static doSomething()I</code></li>
  </ul>
  
  <p>My questions are:</p>
  
  <ul>
  <li><p>I have an enum class, and I want to return an enum instace given an enum variable, for instance, findById <code>(enum(id, color))</code>. How would I do it? Companion Object? object?</p></li>
  <li><p>It seems the only way to have a real static method is in package level, without class declaration. But that becomes a little bit too global. Is there any way to access it via: <code>ClassName.staticMethod</code>, staticMethod being really static.</p></li>
  <li><p>Provide meaningfull examples of package declaration methods, companion object and object.</p></li>
  </ul>
  
  <p>Context. I have been coding in Kotlin and I find it amazing. But sometimes I need to make a decision: for example, a heavy immutable property which in java I would declare as static final, but in Kotlin I find it hard to "find an equivalent".</p>