Extension Function 和 Infix Functions 在 Kotlin/Java 之间是否有性能差异?

huangapple go评论64阅读模式
英文:

Does any has performance difference between Extension Function and Infix Functions in Kotlin/Java

问题

扩展函数和中缀函数之间是否存在性能差异?谢谢。

英文:

something stuck in my head, I would like to ask you here. I searched the web but couldn't find it. Is there any performance difference between Extension Functions and Infix Functions ? Thanks.

答案1

得分: 9

他们是苹果和橙子,关于它们的性能问题实际上没有太多意义。

在大多数情况下,扩展实际上是一个静态函数,其性能与任何其他静态函数相同。

中缀函数只是提供了调用函数的另一种语法方式。中缀函数可以是常规成员函数或扩展。它们与它们的非中缀等效函数具有相同的性能。

英文:

They are apples and oranges and the question about their performance doesn't really make too much sense.

Extension in most cases is effectively a static function and its performance is the same as any other static function.

Infix function simply provides an alternative syntax for calling a function. Infix function could be both a regular member function or an extension. They have the same performance as their non-infix equivalents.

huangapple
  • 本文由 发表于 2023年6月19日 01:58:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76501900.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定