Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameter type must not include a type variable or wildcard

in my android app I use Retrofit 2:

public enum OperationType {
    @SerializedName("payment")
    PAYMENT,
    @SerializedName("payout")
    PAYOUT,
    @SerializedName("transfer")
    TRANSFER
}




fun getOperationsList(typeList: List<OperationType>, callback: Callback<List<Operation>>) {
        val call = myRestClient.getOperationsList(typeList)
        executeRequest(call, callback)
}


@GET("/operations")
fun getOperationsList(@Query("type") typeList: List<OperationType>): Call<List<Operation>>

but I get runtime error in this line:

val call = myRestClient.getOperationsList(typeList)

error:

Shutting down VM
 FATAL EXCEPTION: main
 Process: md.qsystems.android.tango.debug, PID: 22714
 java.lang.IllegalArgumentException: Parameter type must not include a type variable or wildcard: java.util.List<? extends OperationType> (parameter #1)
     for method TangoRestClient.getOperationsList
    at retrofit2.Utils.methodError(Utils.java:52)
    at retrofit2.Utils.methodError(Utils.java:42)
    at retrofit2.Utils.parameterError(Utils.java:61)
    at retrofit2.RequestFactory$Builder.validateResolvableType(RequestFactory.java:764)
    at retrofit2.RequestFactory$Builder.parseParameterAnnotation(RequestFactory.java:401)
    at retrofit2.RequestFactory$Builder.parseParameter(RequestFactory.java:306)
    at retrofit2.RequestFactory$Builder.build(RequestFactory.java:193)
    at retrofit2.RequestFactory.parseAnnotations(RequestFactory.java:67)
    at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:26)
    at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170)
    at retrofit2.Retrofit$1.invoke(Retrofit.java:149)
    at java.lang.reflect.Proxy.invoke(Proxy.java:393)
    at $Proxy1.getOperationsList(Unknown Source)
    at mTransportService.getOperationsList(TransportService.kt:160)
like image 665
Alexei Avatar asked Aug 06 '19 11:08

Alexei


1 Answers

You can add @JvmSuppressWildcards either inside the angle brackets before the String type, or before the List. Both should work and remove the wildcard.

Workaround taken from this issue.

like image 67
faranjit Avatar answered Nov 11 '22 09:11

faranjit