Hacker News new | past | comments | ask | show | jobs | submit login

With the interface keyword (java/c#).

You just define the required methods and that's the interface.






Think again about fromString, that would be a static constructor method. The GP is looking at metaclasses.

I'm not going to attempt to speak for java, but at least in C#, it supports virtual static methods in interfaces, including generics.

So, as I stated, you would use the interface keyword.

  public interface IFromString<T>
  {
      static abstract T FromString(string value);
  }

  public struct MyHasFromString : IFromString<MyHasFromString>
  {
      public string Text = "";

      public MyHasFromString(string value) 
      {
          Text = value;
      }

      public static MyHasFromString FromString(string value)
          => return new MyHasFromString(value);

      public override string ToString() => Text;
  }



Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: