Groovy web console

subscribe to the feed Subscribe
to this
site

Meta Object Programming - 1

Published 5 months ago by Deepankar with tags meta object programming MOP
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import java.lang.Character
class Run
{
    public static void main(String[] args)
    {
        String.getMetaClass().findASCII << {            
            String result = ""
            Integer ascii = 0
            for(Integer i = 0; i <= delegate.length()-1; i++)
            {
                ascii = delegate[i]
                result = result + delegate[i] + "[" + ascii + "]."
            }
            println result
        }
        try
        {
            //println args[0].findASCII() - "Can be provided from console.
            println "abcd".findASCII()
        }
        catch(ArrayIndexOutOfBoundsException exception)
        {
            println exception.toString()
        }
    }
}