private void Store() { quotient_Float = posture_error/time; if(value.getFloat("Value_Quotient", quotient_Float)==null || quotient_Float < value.getFloat("Value_Quotient", quotient_Float)) { editor.putFloat("Value_Quotient", quotient_Float); editor.commit(); } }
float是原始数据类型,而不是对象. null检查用于对象.对于基元,您应该使用默认值检查.对于float,默认值为0.0f.
翻译自:https://stackoverflow.com/questions/18492432/in-java-how-do-you-check-if-a-float-variable-is-null