无法抗拒并对其进行了测试,而且看起来几乎没有开销。
参加者有:
Interface IFoo defining a method
class Foo: IFoo implements IFoo
class Bar implements the same method as Foo, but no interface involved
所以我定义
Foo realfoo = new Foo();
IFoo ifoo = new Foo();
Bar bar = new Bar();
然后调用该方法,该方法执行20个字符串连接,每个变量进行10,000,000次。
realfoo: 723 Milliseconds
ifoo: 732 Milliseconds
bar: 728 Milliseconds
realfoo: 48 Milliseconds
ifoo: 62 Milliseconds
bar: 49 Milliseconds