title: Which is the preferred syntax when using annotation-based dependency injection in Kotlin?
body: <p>We're using an existing framework which - among other things - provides dependency injection through annotations. In Java, to inject field value we would do something like this:</p>
  
  <pre><code>@Inject private SomeService someService;
  </code></pre>
  
  <p>Since reflection allows to reassign fields that are normally final, this also a valid declaration:</p>
  
  <pre><code>@Inject private final SomeService someService = null;
  </code></pre>
  
  <p>To make the declaration even shorter (and also make the fields available in unit test classes, while keeping them a part of semi-private API), you could do it like this:</p>
  
  <pre><code>@Inject SomeService someService;
  @Inject final SomeService someService;
  </code></pre>
  
  <p>When it comes to Kotlin, we're stuck with this:</p>
  
  <pre><code>@Inject private var someService: SomeService? = null
  @Inject private lateinit var someService: SomeService
  </code></pre>
  
  <ul>
  <li>Nullable type approach requires additional null check (or <code>!!</code> operator) on every service use, even though we're 100% sure they will never be null - unless something went completely wrong, in which case we have bigger problems.</li>
  <li><code>lateinit</code> approach seems to perform unnecessary checks at runtime (which are, well, highly unlikely to become performance bottlenecks, but still) and is rather verbose.</li>
  <li>Both approaches allow to reassign the variable to another value. We're yet to find a way of replacing <code>var</code> with <code>val</code> without overriding getter or using a back-up field, which faces the same problem. Ironically, they are both longer than Java declarations in many cases.</li>
  </ul>
  
  <p>So - what is the preferred way of declaring annotated Kotlin fields, which will be injected automatically and we're 100% sure that they will never be null?</p>
  
  <p>While I understand that there are multiple frameworks with Kotlin-friendly syntax solving similar problems (like <a href="https://github.com/kohesive/injekt" rel="nofollow">Injekt</a>), I'm asking if there's a nicer way of doing it with what we have.</p>