Groovy Extension String Class

Groovy allows you to do nice things with lines on external pages, for example:

${"hello".capitalize()}

How to add a new custom method to String class? How:

${"hello".custom()}

+6
source share
1 answer

Use metaClass

 String.metaClass.custom = { //dosomething } 

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

+7
source

Source: https://habr.com/ru/post/914375/


All Articles