title: How to override method when instantiating object in Kotlin?
body: <p>In Java, to override method when instantiating new object we can do this</p>
  
  <pre><code>public ActivityTestRule&lt;MainActivity&gt; rule = new ActivityTestRule&lt;MainActivity&gt;(
              MainActivity.class) {
          @Override
          protected void beforeActivityLaunched() {
              // implement code
              super.beforeActivityLaunched();
          }
      };
  </code></pre>
  
  <p>How to do that in Kotlin? I tried this code but it failed to compile.</p>
  
  <pre><code>@Rule @JvmField
  var rule = ActivityTestRule&lt;MainActivity&gt;(MainActivity::class.java) {
      override fun beforeActivityLaunched() {
          super.beforeActivityLaunched()
      }
  } 
  </code></pre>