#How does Class::new work?

9 messages · Page 1 of 1 (latest)

split robin
#

What does ::new do exactly? And, if there is more than one constructor in the class that ::new is operating on, what happens?

serene cargoBOT
#

This post has been reserved for your question.

Hey @split robin! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

split robin
#

in particular, say i had something like this:

class Foo {
  private final int x;
  private final int y;

  public Foo(int x, int y) {
    this.x = x;
    this.y = y;
  }

  public Foo(int x) {
    this(x, 0);
  }
}

what would Foo::new do?

#

which constructor does it use? is there a way to specify?

spare temple
#

Well, I am pretty sure you can't use it outside of the stream api, because you would need 2 values to be able to pass it in. And like I explained n the bot commands channel

split robin
#

ye ur right

#

thank u very much

serene cargoBOT
# split robin thank u very much

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.