You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
The problem here is that the wildcards types can not be compiled as-is since they are bounded by boxed primitives and strings. This compiler produces the following error:
incompatible types: Map<String,CAP#1> cannot be converted to Map<String,String>
return HANDLER.handleRequest(input,context);
^
where CAP#1 is a fresh type-variable:
CAP#1 extends String from capture of ? extends String
The workaround I've implemented is to recursively iterate through the Parameterized type and replace the invalid wildcard types:
privatefun TypeName.ensureProperWildcards(): TypeName=when (this) {
isParameterizedTypeName-> {
ParameterizedTypeName.get(this.rawType, *this.typeArguments.map {
it.ensureProperWildcards()
}.toTypedArray())
}
isWildcardTypeName-> {
val firstUpperBound =this.upperBounds.firstOrNull()
val firstLowerBound =this.lowerBounds.firstOrNull()
if (firstUpperBound !=null&& (firstUpperBound ==TypeName.get(String::class.java) || firstUpperBound.isBoxedPrimitive) && firstLowerBound ==null) {
firstUpperBound
} else {
this
}
}
else-> {
this
}
}
Could this be avoided when Javapoet parses the TypeMirror and removes the wildcard for boxed primitives and strings?
The text was updated successfully, but these errors were encountered:
@richarddd not a 100% sure what version you are using, but did some research and it seem that JavaPoet from version 1.10.0 doesn’t support code compilation.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi,
I have a bunch of annotate generic Kotlin classes with Maps as parameters.
The class looks like this:
The TypeMirror looks something like this:
com.example.ExampleClass<java.util.Map<java.lang.String,? extends java.lang.String>,java.util.Map<java.lang.String,? extends java.lang.Integer>>
The problem here is that the wildcards types can not be compiled as-is since they are bounded by boxed primitives and strings. This compiler produces the following error:
The workaround I've implemented is to recursively iterate through the Parameterized type and replace the invalid wildcard types:
Could this be avoided when Javapoet parses the TypeMirror and removes the wildcard for boxed primitives and strings?
The text was updated successfully, but these errors were encountered: