Java stream map call another constructor [duplicate]












1
















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;
}









share|improve this question













marked as duplicate by user7, Mark Rotteveel java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

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
















1
















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;
}









share|improve this question













marked as duplicate by user7, Mark Rotteveel java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

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














1












1








1









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;
}









share|improve this question















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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 4:50









Ben LukBen Luk

3101313




3101313




marked as duplicate by user7, Mark Rotteveel java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

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 java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

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



















  • 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












2 Answers
2






active

oldest

votes


















2














ids.stream().map(id -> new AccountPermissionsUpdate(id, true));


You will call it like this.






share|improve this answer































    2














    Try out below code:



    ids.stream().map(element -> new AccountPermissionsUpdate(element,true));





    share|improve this answer





















    • 1





      Wow you are fast, but the id seem not correct here, should be element?

      – 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




















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    ids.stream().map(id -> new AccountPermissionsUpdate(id, true));


    You will call it like this.






    share|improve this answer




























      2














      ids.stream().map(id -> new AccountPermissionsUpdate(id, true));


      You will call it like this.






      share|improve this answer


























        2












        2








        2







        ids.stream().map(id -> new AccountPermissionsUpdate(id, true));


        You will call it like this.






        share|improve this answer













        ids.stream().map(id -> new AccountPermissionsUpdate(id, true));


        You will call it like this.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 4:55









        Dang NguyenDang Nguyen

        863623




        863623

























            2














            Try out below code:



            ids.stream().map(element -> new AccountPermissionsUpdate(element,true));





            share|improve this answer





















            • 1





              Wow you are fast, but the id seem not correct here, should be element?

              – 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


















            2














            Try out below code:



            ids.stream().map(element -> new AccountPermissionsUpdate(element,true));





            share|improve this answer





















            • 1





              Wow you are fast, but the id seem not correct here, should be element?

              – 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
















            2












            2








            2







            Try out below code:



            ids.stream().map(element -> new AccountPermissionsUpdate(element,true));





            share|improve this answer















            Try out below code:



            ids.stream().map(element -> new AccountPermissionsUpdate(element,true));






            share|improve this answer














            share|improve this answer



            share|improve this answer








            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 the id seem not correct here, should be element?

              – 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





              Wow you are fast, but the id seem not correct here, should be element?

              – 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





            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python