I\'m trying to eliminate all the warnings of my Android application and one of them is this:
viewModel.value is a boxed field but needs to be un-boxed
I find a code ,this this safeUnbox implementation。
/** @hide */
protected static int safeUnbox(java.lang.Integer boxed) {
return boxed == null ? 0 : (int)boxed;
}
/** @hide */
protected static long safeUnbox(java.lang.Long boxed) {
return boxed == null ? 0L : (long)boxed;
}
/** @hide */
protected static short safeUnbox(java.lang.Short boxed) {
return boxed == null ? 0 : (short)boxed;
}
/** @hide */
protected static byte safeUnbox(java.lang.Byte boxed) {
return boxed == null ? 0 : (byte)boxed;
}
/** @hide */
protected static char safeUnbox(java.lang.Character boxed) {
return boxed == null ? '\u0000' : (char)boxed;
}
/** @hide */
protected static double safeUnbox(java.lang.Double boxed) {
return boxed == null ? 0.0 : (double)boxed;
}
/** @hide */
protected static float safeUnbox(java.lang.Float boxed) {
return boxed == null ? 0f : (float)boxed;
}
/** @hide */
protected static boolean safeUnbox(java.lang.Boolean boxed) {
return boxed == null ? false : (boolean)boxed;
}
so ,if you value is not base type,you can not direct use safeUnbox,you should define a static function to safe unbox by youself.