简体   繁体   中英

“Key-Value Coding” for Java

In Objective-C on Apple there is something called "Key-Value Coding" that allows you to traverse the object graph using strings similar to filesystem paths. There's an informal protocol (ie interface) that allows objects to return values based on the "key" they're asked for. eg The default is to return the value of a field named by the key, while relational collections like NSDictionaries can implement more interesting behavior.

Pseudo code example:

foo.bar = new baz();
foo.bar.mymap = new map();
foo.bar.mymap['bom'] = 2;

foo.valueForKeyPath("bar.mymap.bom") # 2

Is there anything like this for Java? It would be easy enough to implement, but I thought I'd look first.

PropertyUtils.getProperty ,从Apache的BeanUtils的图书馆,这是否对JavaBean属性。

Hmm, well, in case anyone else has this question, it looks like MVEL is a good bet:

http://mvel.codehaus.org/Property+Navigation

Ujorm是一个开源Java库,提供基于键值架构的对象,请参阅示例

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM