lodash .get()函数的轻量级Java实现 [英] Lightweight Java implementation of lodash .get() function

查看:58
本文介绍了lodash .get()函数的轻量级Java实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在访问Android项目中深层嵌套的json对象,并且我不想做4次以上的null检查来引用特定的对象.

I'm accessing deeply nested json objects in an Android project, and I'd like to not have to do upwards of 4 null checks to reference specific objects.

在JS中,Lodash具有 .get()函数,该函数使访问这些内容更加简洁.Java有类似的可用功能吗?

In JS, Lodash has the .get() function, which makes accessing those contents much more concise. Is there something similar available for Java?

FWIW,我编写了一个实现使用反射.由于Reflection固有的性能影响,因此对于热代码路径而言,这可能不是一个很好的选择.有兴趣看到替代方案.

edit: FWIW, I wrote an implementation of this using Reflection. Because of the inherent performance hit of Reflection, this is probably not a good candidate for hot code paths. Would be interested to see alternatives.

推荐答案

尝试一下- https://javadev.github.io/underscore-java/.它是Java中的underscore.js,带有 find().

Try this - https://javadev.github.io/underscore-java/. It's underscore.js in java with find().

这篇关于lodash .get()函数的轻量级Java实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆