15

Recently I had a problem with @Named qualifier in Kotlin. I thought that changing from this:

var boldTypeface: Typeface? = null
[Inject] set

into this

var boldTypeface: Typeface? = null
[Inject Named("bold")] set

or

var boldTypeface: Typeface? = null
[Inject] [Named("bold")] set

would solve my problem. But it didn't, it's not even compiling.

Damian Petla
  • 8,963
  • 5
  • 44
  • 47

1 Answers1

35

I had to update my answer since Kotlin improved a lot. Right now I am using Kotlin 1.0 beta 3

To properly set multiple annotations for a property you have to use @field annotation:

@field:[Inject Named("bold")]
lateinit var boldTypeface: Typeface

Note that I am using lateinit here so there is no need to use nullable type Typeface?

Damian Petla
  • 8,963
  • 5
  • 44
  • 47
  • 3
    CAn you please update the code sample to use the current annotation syntax of `@Inject` and `@Named("bold")` – Jayson Minard Jan 02 '16 at 03:03
  • @JaysonMinard I would but what exactly is wrong with it? I see similar approach in Kotlin's docs http://kotlinlang.org/docs/reference/annotations.html#annotation-use-site-targets – Damian Petla Sep 04 '17 at 08:35
  • You already did the edit (Jan 5) after my comment to the correct format. – Jayson Minard Sep 13 '17 at 21:08