因为知道他底层还是在jvm上运行的所以应该有个函数入口main函数于是反编译看看他的class
在d盘下新建:Hello.groovy
println 'hello world'
groovyc Hello.groovy
生成Hello.class
反编译后:
import groovy.lang.Binding;
import groovy.lang.Script;
import org.codehaus.groovy.runtime.ScriptBytecodeAdapter;
import org.codehaus.groovy.runtime.callsite.CallSite;
import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
public class Hello extends Script
{
public Hello()
{
Hello this;
CallSite[] arrayOfCallSite = $getCallSiteArray();
}
public Hello(Binding arg1)
{
Binding context;
CallSite[] arrayOfCallSite = $getCallSiteArray();
ScriptBytecodeAdapter.invokeMethodOnSuperN($get$$class$groovy$lang$Script(), this, "setBinding", new Object[] { context });
}
public static void main(String[] args)
{
CallSite[] arrayOfCallSite = $getCallSiteArray();
arrayOfCallSite[0].call($get$$class$org$codehaus$groovy$runtime$InvokerHelper(), $get$$class$Hello(), args);
}
public Object run()
{
CallSite[] arrayOfCallSite = $getCallSiteArray(); return arrayOfCallSite[1].callCurrent(this, "hello world"); return null;
}
static
{
__$swapInit();
Long localLong1 = (Long)DefaultTypeTransformation.box(0L);
__timeStamp__239_neverHappen1330265162012 = localLong1.longValue();
Long localLong2 = (Long)DefaultTypeTransformation.box(1330265162012L);
__timeStamp = localLong2.longValue();
}
}
初步一看应该是main中调用无参构造函Hello生成Hello对象,然后调用run()方法。其他对象待查看api,源码来慢慢理解消化。