Once triggered NaN npe

First on the code #

Import com.alibaba.fastjson.JSON;
 Import com.alibaba.fastjson.JSONObject; 

public  class QQ { 

    public  static  void main (String [] args) {
         Double Result = calcute () <0 0? : calcute (); 
        the System. out.println (the Result); 
        ResultBean resultBean = new new ResultBean (the Result); 
        System.out.println (resultBean.toString ()); 
        // if resultBean.value then be calculated, then you'll notice a bunch npe, and you do not necessarily know where the problem in the end. . . 
        = JsonObject the JSONObject JSON.parseObject (resultBean.toString ()); 
        System.out.println (jsonObject.get ( "value"));
    }

    public static double calcute() {
        Double temp1 = 1d;
        Double temp2 = 2d;
        double temp3 = temp1 - temp2;
        double temp4 = Math.sqrt(temp3);
        double result = ((temp1 + temp4) / temp2);
        return result;
    }
}

class ResultBean {

    private double value;

    public ResultBean(double value) {
        this.value = value;
    }

    public double getValue() {
        return value;
    }

    public void setValue(double value) {
        this.value = value;
    }

    public String toString() {
        Object result = JSON.toJSON(this);
        return result.toString();
    }

}

# Of course, I just put the main logic brought up, the actual project also mixed with other complex logic

# The above code is the result of:

NaN
{"value":null}
null

# Java Bean can be seen when the transfer jsonStr, NaN to the erased, which gives the back and then troubleshoot the problem appears npe caused great difficulties. . . . .

Guess you like

Origin www.cnblogs.com/lwmp/p/11024664.html