解决繁琐判null办法 : Optional类

http://www.importnew.com/22060.html

            tick2 = Optional.ofNullable(JSON.parseObject(tickJson.toString(), Tick2.class));
            String lastTickDirection = tick2.map(t -> t.getData()).map(d -> d.get(0)).map(l -> l.getLastTickDirection()).orElse("");
            if (lastTickDirection.equals("PlusTick")) {
                lastPrice = tick2.map(t -> t.getData()).map(d -> d.get(0)).map(l -> l.getLastPrice()).orElse(0d);
                if (Double.doubleToLongBits(lastPrice) == Double.doubleToLongBits(0)) {return null;}

你可能感兴趣的:(解决繁琐判null办法 : Optional类)