Java编码规范-字符串与Integer的比较,BigDecimal非空参数

发布时间 2023-04-22 11:49:34作者: oktokeep

Java编码规范-字符串与Integer的比较,BigDecimal非空参数

package com.example.core.mydemo;

import java.math.BigDecimal;

public class IntTest {
    public static void main(String[] args) {
        Integer type = 2;
//        if("2".equals(type)) {
        if(type == 2) {
            System.out.println("type=" + type);
        }else{
            System.out.println("111");
        }


        /**
         * 报空了:
         * ss=null
         * Exception in thread "main" java.lang.NullPointerException
         *     at com.example.core.mydemo.IntTest.main(IntTest.java:17)
         */
        Integer ss = null;
        System.out.println("ss=" + ss);
        BigDecimal g = new BigDecimal(ss);
        System.out.println("g="+ g);
    }
}