简体   繁体   中英

Extending Groovy String class

Groovy allows to do some nice things with strings in frontend pages, like:

${"hello".capitalize()}

How can I add a new custom method to the String class? Like:

${"hello".custom()}

Use the metaClass

String.metaClass.custom = { //dosomething }

See http://www.groovyexamples.org/2010/07/19/dynamically-add-properties-to-a-class/

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