Scala equivalent of C#’s extension methods?

前端 未结 5 1777
傲寒
傲寒 2020-12-07 12:09

In C# you can write:

using System.Numerics;
namespace ExtensionTest {
public static class MyExtensions {
    public static BigInteger Square(this BigInteger          


        
5条回答
  •  庸人自扰
    2020-12-07 12:43

    Scala 3 now has extension methods. Functionally it seems similar as expected to C# and Kotlin.

    https://dotty.epfl.ch/docs/reference/contextual/extension-methods.html
    https://github.com/scala/scala
    https://github.com/lampepfl/dotty

    A recent (as of this post) pull shows the syntax being simplified. Stable version as of this post is still 2.x. But there is a 3.xRC, and I noticed Jetbrains already supports it in Idea, partially I assume.

提交回复
热议问题