fable-compiler / repl

Fable online REPL
http://fable.io/repl
MIT License
61 stars 34 forks source link

Update inaccurate comment about Java in the tour #193

Closed ForNeVeR closed 6 months ago

ForNeVeR commented 6 months ago

Java has a feature called anonymous classes that works practically the same as object expressions in F#, and that's a pretty old feature, introduced even before Java 8 I think. Check some examples here.

Before Java 8, that feature was widely used to get something like lambda expressions, but with a tiny bit less terse syntax, like this:

interface MyFunctionLike {
  int run();
}

MyFunctionLike aBitLikeLambda = new MyFunctionLike {
  @Override
  public int run() {
    return 2 + 2;
  }
};

The full analog in F# would be

type MyFunctionLike =
  abstract member run: unit -> int

let aBitLikeLambda =
  { interface MyFunctionLike with
    member _.run() = 2 + 2 }

So, the comment in question is inaccurate, and I suggest to avoid mentioning Java there.