Java stream map call another constructor [duplicate]
This question already has an answer here:
How to pass argument to class constructor when initialzed thru ::new in Java8
2 answers
I am trying to use java stream instead of forloop
ids.stream().map(AccountPermissionsUpdate::new)
I have created an other constructor,
my question is: how to call the second constructor
new AccountPermissionsUpdate(id,true)
Thanks
public AccountPermissionsUpdate(long accountId) {
this.accountId = accountId;
}
public AccountPermissionsUpdate(long accountId, boolean forcedLogout) {
this.accountId = accountId;
this.forcedLogout = forcedLogout;
}
java
marked as duplicate by user7, Mark Rotteveel
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 14:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How to pass argument to class constructor when initialzed thru ::new in Java8
2 answers
I am trying to use java stream instead of forloop
ids.stream().map(AccountPermissionsUpdate::new)
I have created an other constructor,
my question is: how to call the second constructor
new AccountPermissionsUpdate(id,true)
Thanks
public AccountPermissionsUpdate(long accountId) {
this.accountId = accountId;
}
public AccountPermissionsUpdate(long accountId, boolean forcedLogout) {
this.accountId = accountId;
this.forcedLogout = forcedLogout;
}
java
marked as duplicate by user7, Mark Rotteveel
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 14:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Just a side note (learned from Josh Bloch's book Effective Java), stream api is not a replacement for for loops, so be careful as it creates many stream instances in between. You can read more about that in his book though
– Ketan
Nov 16 '18 at 5:06
add a comment |
This question already has an answer here:
How to pass argument to class constructor when initialzed thru ::new in Java8
2 answers
I am trying to use java stream instead of forloop
ids.stream().map(AccountPermissionsUpdate::new)
I have created an other constructor,
my question is: how to call the second constructor
new AccountPermissionsUpdate(id,true)
Thanks
public AccountPermissionsUpdate(long accountId) {
this.accountId = accountId;
}
public AccountPermissionsUpdate(long accountId, boolean forcedLogout) {
this.accountId = accountId;
this.forcedLogout = forcedLogout;
}
java
This question already has an answer here:
How to pass argument to class constructor when initialzed thru ::new in Java8
2 answers
I am trying to use java stream instead of forloop
ids.stream().map(AccountPermissionsUpdate::new)
I have created an other constructor,
my question is: how to call the second constructor
new AccountPermissionsUpdate(id,true)
Thanks
public AccountPermissionsUpdate(long accountId) {
this.accountId = accountId;
}
public AccountPermissionsUpdate(long accountId, boolean forcedLogout) {
this.accountId = accountId;
this.forcedLogout = forcedLogout;
}
This question already has an answer here:
How to pass argument to class constructor when initialzed thru ::new in Java8
2 answers
java
java
asked Nov 16 '18 at 4:50
Ben LukBen Luk
3101313
3101313
marked as duplicate by user7, Mark Rotteveel
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 14:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by user7, Mark Rotteveel
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 14:51
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Just a side note (learned from Josh Bloch's book Effective Java), stream api is not a replacement for for loops, so be careful as it creates many stream instances in between. You can read more about that in his book though
– Ketan
Nov 16 '18 at 5:06
add a comment |
Just a side note (learned from Josh Bloch's book Effective Java), stream api is not a replacement for for loops, so be careful as it creates many stream instances in between. You can read more about that in his book though
– Ketan
Nov 16 '18 at 5:06
Just a side note (learned from Josh Bloch's book Effective Java), stream api is not a replacement for for loops, so be careful as it creates many stream instances in between. You can read more about that in his book though
– Ketan
Nov 16 '18 at 5:06
Just a side note (learned from Josh Bloch's book Effective Java), stream api is not a replacement for for loops, so be careful as it creates many stream instances in between. You can read more about that in his book though
– Ketan
Nov 16 '18 at 5:06
add a comment |
2 Answers
2
active
oldest
votes
ids.stream().map(id -> new AccountPermissionsUpdate(id, true));
You will call it like this.
add a comment |
Try out below code:
ids.stream().map(element -> new AccountPermissionsUpdate(element,true));
1
Wow you are fast, but theid
seem not correct here, should beelement
?
– Dang Nguyen
Nov 16 '18 at 4:57
1
Yes. My bad. It should be element. I will update my answer. I just copied and pasted your code from your question, that's didn't notice that.
– Jignesh M. Khatri
Nov 16 '18 at 4:57
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
ids.stream().map(id -> new AccountPermissionsUpdate(id, true));
You will call it like this.
add a comment |
ids.stream().map(id -> new AccountPermissionsUpdate(id, true));
You will call it like this.
add a comment |
ids.stream().map(id -> new AccountPermissionsUpdate(id, true));
You will call it like this.
ids.stream().map(id -> new AccountPermissionsUpdate(id, true));
You will call it like this.
answered Nov 16 '18 at 4:55
Dang NguyenDang Nguyen
863623
863623
add a comment |
add a comment |
Try out below code:
ids.stream().map(element -> new AccountPermissionsUpdate(element,true));
1
Wow you are fast, but theid
seem not correct here, should beelement
?
– Dang Nguyen
Nov 16 '18 at 4:57
1
Yes. My bad. It should be element. I will update my answer. I just copied and pasted your code from your question, that's didn't notice that.
– Jignesh M. Khatri
Nov 16 '18 at 4:57
add a comment |
Try out below code:
ids.stream().map(element -> new AccountPermissionsUpdate(element,true));
1
Wow you are fast, but theid
seem not correct here, should beelement
?
– Dang Nguyen
Nov 16 '18 at 4:57
1
Yes. My bad. It should be element. I will update my answer. I just copied and pasted your code from your question, that's didn't notice that.
– Jignesh M. Khatri
Nov 16 '18 at 4:57
add a comment |
Try out below code:
ids.stream().map(element -> new AccountPermissionsUpdate(element,true));
Try out below code:
ids.stream().map(element -> new AccountPermissionsUpdate(element,true));
edited Nov 16 '18 at 4:57
answered Nov 16 '18 at 4:54
Jignesh M. KhatriJignesh M. Khatri
501411
501411
1
Wow you are fast, but theid
seem not correct here, should beelement
?
– Dang Nguyen
Nov 16 '18 at 4:57
1
Yes. My bad. It should be element. I will update my answer. I just copied and pasted your code from your question, that's didn't notice that.
– Jignesh M. Khatri
Nov 16 '18 at 4:57
add a comment |
1
Wow you are fast, but theid
seem not correct here, should beelement
?
– Dang Nguyen
Nov 16 '18 at 4:57
1
Yes. My bad. It should be element. I will update my answer. I just copied and pasted your code from your question, that's didn't notice that.
– Jignesh M. Khatri
Nov 16 '18 at 4:57
1
1
Wow you are fast, but the
id
seem not correct here, should be element
?– Dang Nguyen
Nov 16 '18 at 4:57
Wow you are fast, but the
id
seem not correct here, should be element
?– Dang Nguyen
Nov 16 '18 at 4:57
1
1
Yes. My bad. It should be element. I will update my answer. I just copied and pasted your code from your question, that's didn't notice that.
– Jignesh M. Khatri
Nov 16 '18 at 4:57
Yes. My bad. It should be element. I will update my answer. I just copied and pasted your code from your question, that's didn't notice that.
– Jignesh M. Khatri
Nov 16 '18 at 4:57
add a comment |
Just a side note (learned from Josh Bloch's book Effective Java), stream api is not a replacement for for loops, so be careful as it creates many stream instances in between. You can read more about that in his book though
– Ketan
Nov 16 '18 at 5:06