Is there any why to avoid "transform variables into final one element array"
public static String getSimSerialNumber(Context context) {
final TelephonyManager tm =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String mSimSerialNumber; // <----- (here the compiler ask for transformation)
if (tm != null) {
RxPermissions.getInstance(context)
.requestEach(Manifest.permission.CAMERA, Manifest.permission.READ_PHONE_STATE)
.subscribe(new Action1<Permission>() {
@Override public void call(Permission permission) {
if (permission.granted) mSimSerialNumber = tm.getSimSerialNumber();
}
});
}
return null;
}
Edit 1 If I accept the solution suggeseted by the compiler the code will be like following :
public static String getSimSerialNumber(Context context) {
final TelephonyManager tm =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String[] mSimSerialNumber = new String[1];
if (tm != null) {
RxPermissions.getInstance(context)
.requestEach(Manifest.permission.CAMERA, Manifest.permission.READ_PHONE_STATE)
.subscribe(new Action1<Permission>() {
@Override public void call(Permission permission) {
if (permission.granted) mSimSerialNumber[0] = tm.getSimSerialNumber();
}
});
}
return null;
}
I think there is a way to avoid using an array (as we know array is used to store more than one element that's why we use array) to solve this problem ?