0

I want to convert some java code to kotlin. this is my code wanna convert.

/*Create handle for the RetrofitInstance interface*/
    GetDataService service = RetrofitClientInstance.getRetrofitInstance().create(GetDataService.class);

And this is class i made.

class RetrofitClientInstance {

    var retrofit: Retrofit?=null
    var BASE_URL = "10.80.7.30:3000"

     fun getRetrofitInstnace() :Retrofit {
        if (retrofit == null) {
            retrofit = retrofit2.Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build()
        }
        return retrofit!!
    }

}

interface MovieService {

    @GET("/movie/:id/script")
    fun getCurrentMovieData(
        @Path("id") id : Int
    ) : Call<Movie>

    @GET("/movie/script")
    fun getMoviesData() : Call<List<Movie>>
}

Please help me anytime!!!!!

1
  • Improve formatting Commented Oct 3, 2019 at 5:04

2 Answers 2

2

If you're using Android Studio, you can just:

  • Configure Kotlin in project
  • Right-click on .java file and select 'Convert Java File to Kotlin File'

If you copy paste the Java snippet into .kt file, it will also ask you if you want to convert it automatically.

Sign up to request clarification or add additional context in comments.

Comments

1

Your above java code should be like the following.

var service = RetrofitClientInstance.getRetrofitInstance().create(GetDataService::class.java)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.