title: Kotlin - idiomatic way to create a Fragment newInstance pattern
body: <p>The best practice on Android for creating a <code>Fragment</code> is to use a static factory method and pass arguments in a <code>Bundle</code> via <code>setArguments()</code>. </p>
  
  <p>In Java, this is done something like:</p>
  
  <pre><code>public class MyFragment extends Fragment {
      static MyFragment newInstance(int foo) {
          Bundle args = new Bundle();
          args.putInt("foo", foo);
          MyFragment fragment = new MyFragment();
          fragment.setArguments(args);
          return fragment;
      }
  }
  </code></pre>
  
  <p>In Kotlin this converts to:</p>
  
  <pre><code>class MyFragment : Fragment() {
      companion object {
         fun newInstance(foo: Int): MyFragment {
              val args = Bundle()
              args.putInt("foo", foo)
              val fragment = MyFragment()
              fragment.arguments = args
              return fragment
          }
      }
  }
  </code></pre>
  
  <p>This makes sense to support interop with Java so it can still be called via <code>MyFragment.newInstance(...)</code>, but is there a more idiomatic way to do this in Kotlin if we don't need to worry about Java interop?</p>