As you can see from Figure 1, the generated code executes much faster than reflection in every case.
从图1中可以看出,不管在什么情况下,生成的代码执行都比反射要快得多。
I also wrote a similar timing test program for creating objects using reflection. The differences for this case aren't nearly as significant as for the field and method call cases, though.
我还为创建使用反射的对象编写了类似的计时测试程序,但这种情况下的差异不象字段和方法调用情况下那么显著。
In their case, they avoided using reflection by instead working directly with class files, adding code to the classes generated by the compiler in order to provide direct access for the framework.
在他们的情况中,通过直接处理类文件,同时向编译器所生成的类添加代码以便为框架提供直接访问,来避免使用反射。
应用推荐