Can a class method return the current instance of its class?

Like return this; or return new ClassName(this) or something like that…

Of course I tried and it didn’t work, so I thought I’d ask if it’s possible.

I’ve made a new Line class, and the following seems to work, I was just hoping for a shortcut to avoid having to call a constructor.

Line getLine() {
      return new Line(x1, y1, x2, y2);
1 Like

You can use clone() in place of new: :space_invader:


Nice, thanks for the explanation in the link

1 Like