-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using kotlin mutable collections for typenames #279
Comments
This might be a problem with Kotlin itself.
|
... looks like
|
should this be something kotlinpoet addresses then? given your findings its probably impossible to have something thats safe at compile time |
|
Yeah something like... fun KClass<*>.asMutableTypeName(): ClassName {
return when (this) {
List::class -> MUTABLE_LIST
Map::class -> MUTABLE_MAP
Set::class -> MUTABLE_SET
else -> asTypeName()
}
} ...is handy |
@afollestad btw we've introduced a large number of constants for frequently used fun KClass<*>.asMutableTypeName(): ClassName {
return when (this) {
List::class -> MUTABLE_LIST
Map::class -> MUTABLE_MAP
Set::class -> MUTABLE_SET
else -> asTypeName()
}
} |
This, annoyingly, isn't covered by the new @Test
fun typeNameOf_mutable() {
val type = typeNameOf<MutableList<String>>()
assertThat(type.toString()).isEqualTo("kotlin.collections.MutableList<kotlin.String>")
} yields
|
This is filed now https://youtrack.jetbrains.com/issue/KT-35877 |
facing the same problem, no way to create a property with MutableList type, please help |
Did you actually read the issue?
|
If I do
the generated code uses
kotlin.collections.List
I have worked around with
ClassName("kotlin.collections", "MutableList")
The text was updated successfully, but these errors were encountered: