The new `typeOf` intrinsic does not retain type an...
# announcements
d
The new
typeOf
intrinsic does not retain type annotations. Is this intended or a bug?
e
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
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
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
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
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
It requires kotlin-reflect, sadly
e
Inline classes will cover the validation use-case and will support init for that.
d
Inline classes don't allow initializer blocks.
e
Yet.
d
oh. That's good to know! Thank you