When using the GroovyClassLoader, when should I use loadClass and when should I call parseClass?
If I understand it, the first call to loadClass() will compile the script, and subsequent calls will use the cached class file rather than recompiling it.
But what about parseClass then?
The documentation for
parseClassshows that it takes a File or a String containing Groovy code, and converts it into a class.If the function is passed a File, then the GroovyClassLoader will cache this generated class, but if it is passed a String, it will not cache it.
The function
loadClass(from the documentation) says:What it basically does, is looks for the class already existing in the classLoader, and if it fails to find it, look for the script file on disk with the matching name.
Once this class is loaded, it will be cached. The next time you call
loadClass, it will use this cached class unless you passfalsefor thepreferClassOverScript. If you passfalse, it will attempt locate the script on disk again, recompile the class if necessary.