Variables with Kotlin

1

I'm trying to complete a url by means of variables but when I pass it and add it to the url I want to connect to, it gives me an error

override fun onCreate
    var mparam = intent.getStringExtra("param")

object Detalles {
        const val COD_INFO: String = mparam
    }

interface ApiActaPartido {
                 @GET("My_url"+COD_INFO)
                 fun getActaPartido(): Call<ActaPartidoList>    
            } 

mparam marks me in red: initialiter should be a constan value

How can I solve it?

    
asked by Rafel C.F 29.12.2017 в 10:17
source

2 answers

0

In Kotlin, const is used to mark constants whose value is known at compile time .

That means that the value of mparam should be known at compile time. You get that value at runtime, with a Intent , I guess.

The solution I can think of is to uncheck COD_INFO as constant at compile time and leave it like this:

val COD_INFO : String = mparam
    
answered by 02.01.2018 в 11:05
0

I think that the object that you are creating is to access the variable from some other class, I would do it in the following way

object

companion object { lateinit var COD_INFO: String }

onCreate

COD_INFO = intent.getStringExtra("param")

and then in the function you want to call both

val x = "My_url$COD_INFO"

I hope it works for you.

    
answered by 09.01.2018 в 00:58