https://kotlinlang.org logo
#announcements
Title
# announcements
d

diesieben07

06/24/2019, 10:13 AM
The new
typeOf
intrinsic does not retain type annotations. Is this intended or a bug?
e

elizarov

06/24/2019, 10:31 AM
It is intended (thus far). However, it might be added in the future. Feel free to submit a feature request. What’s your use case for type annotations?
d

diesieben07

06/24/2019, 10:36 AM
I don't have one specifically for
typeOf
, but it's another nail in the coffin for type annotations. They are not retained for Java reflection and even the previous workaround for
typeOf
(anonymous object in an inline function) does not retain them.
I just feel they never get the love they deserve
e

elizarov

06/24/2019, 10:40 AM
But what kind of love type annotations deserve? What would you be doing with them?
(I mean, I can come up with a few potential uses myself, but I’m interested in learning what would be the realistic use-cases in the context of
typeOf
operator)
d

diesieben07

06/24/2019, 11:24 AM
Like I said, don't have anything for
typeOf
(yet?), but what I would love to be able to do is something like:
val x: List<@SomeValidation String>
If inline classes allowed some kind of
init
(or an internal constructor) that would solve that validation issue. But in general it's sad that the annotations are supported in the language, but only half.
p

Paul Woitaschek

06/24/2019, 12:06 PM
Can I sommehow retrieve the java type by typeOf?
I would love to use it with moshi:
Copy code
@CheckReturnValue public <T> JsonAdapter<T> adapter(Type type) {
    return adapter(type, Util.NO_ANNOTATIONS);
  }
j

jw

06/24/2019, 2:11 PM
It requires kotlin-reflect, sadly
e

elizarov

06/24/2019, 5:00 PM
Inline classes will cover the validation use-case and will support init for that.
d

diesieben07

06/26/2019, 6:46 AM
Inline classes don't allow initializer blocks.
e

elizarov

06/26/2019, 7:22 AM
Yet.
d

diesieben07

06/26/2019, 7:26 AM
oh. That's good to know! Thank you
3 Views