I declare a final variable in global
public static final String USERTYPE="customer"
Then I use this variable as
@POST
@Headers({
"Content-Type: application/json;charset=utf-8",
"Accept: application/json;charset=utf-8",
"Cache-Control: max-age=640000",
"user-type: " + APIService.STRING
})
Call<ReturnPojo> addpost(@Url String s, @Body Add body);
Later in my program, I need to change the
USERTYPE="guest"
I try
1.USERTYPE.replace("customer","guest");
2.String user="customer"
USERTYPE=user;
How can I achieve this? or How to change a final variable in java?
Change Header on Run-time(Retrofit API)
We cannot change the final variable, So we cannot change the user type programmatically. By duplicating the code is not good practice. But we can be done through this,
@POST
Call<ReturnPojo> addpost(@Url String s,
@Body Add body,
@Header("user-type") String user_type,
@Header("Content-Type") String content_type,
@Header("Accept") String accept,
@Header("Cache-Control") String cache_controller);
And finally, while we call API just pass the data as the parameter.