Stream in orElse of optional












3















I am trying to use a Stream in orElse and having difficulty in understanding the error.



collectorConfiguration = Optional.ofNullable(recapPlacement.getAttId())
.map(attId -> Optional.ofNullable(processorEngine.buildFrimFromAttId(attId))
.orElseThrow( () -> new OmegaException("UnableToFirmByAttId", recapPlacement.getAttId())))
.orElse( () -> Optional.ofNullable(collectorConfigurations.stream() //getting error here
.filter(cc -> recapPlacement.getPnetCode().equals(cc.getPnetCode()))
.filter(Objects::nonNull)
.findFirst())
.orElseThrow( () -> new OmegaException("CollectorCouldNotMapForPnetCode", recapPlacement.getPnetCode()))
);


Overall in the above code I am trying to




  1. get collectorConfig if attId is not null


  2. if attId is not null and collectorConfig not found for that attId then I am throwing exception


  3. if attId is null then I am using pnet code to get collectConfig by streaming collectConfigurations list


  4. if collectConfig is not found for pnetCode then I am throwing exception



It is giving a compilation error 'Target type of a lambda expression must be an interface' in the orElse block.










share|improve this question




















  • 1





    Whats the error?

    – Nicholas K
    Nov 21 '18 at 16:13











  • Target type of a lambda expression must be an interface

    – arjun
    Nov 21 '18 at 16:17






  • 1





    Getting complex stream pipelines to compile can be tricky. There are some generally useful problem-solving techniques: 1) Add parameter types to all lambdas: (ArgType arg) -> .... 2) Add explicit type parameter to methods: <ArgType>.orElse(...). 3) Extract whole lambdas to local variables. The locals often look like this: Function<Arg1, Arg2> = ..., which makes it easy to set explicit type arguments. Applying these techniques often gives a more precise compilation error and help you find the problem. When the problem is fixed the helper types and variables can be removed.

    – Lii
    Nov 21 '18 at 16:23













  • What are the variables used in the code?

    – Mani
    Nov 21 '18 at 16:32






  • 2





    I'd recommend using a plain old if-else test on the result of recapPlacement.getAttId(). The Stream is fine, but the way you use Optional here violates its API notes, and the advice of its author. See The Mother of All Bikesheds for some ways to make your code readable.

    – erickson
    Nov 21 '18 at 17:15
















3















I am trying to use a Stream in orElse and having difficulty in understanding the error.



collectorConfiguration = Optional.ofNullable(recapPlacement.getAttId())
.map(attId -> Optional.ofNullable(processorEngine.buildFrimFromAttId(attId))
.orElseThrow( () -> new OmegaException("UnableToFirmByAttId", recapPlacement.getAttId())))
.orElse( () -> Optional.ofNullable(collectorConfigurations.stream() //getting error here
.filter(cc -> recapPlacement.getPnetCode().equals(cc.getPnetCode()))
.filter(Objects::nonNull)
.findFirst())
.orElseThrow( () -> new OmegaException("CollectorCouldNotMapForPnetCode", recapPlacement.getPnetCode()))
);


Overall in the above code I am trying to




  1. get collectorConfig if attId is not null


  2. if attId is not null and collectorConfig not found for that attId then I am throwing exception


  3. if attId is null then I am using pnet code to get collectConfig by streaming collectConfigurations list


  4. if collectConfig is not found for pnetCode then I am throwing exception



It is giving a compilation error 'Target type of a lambda expression must be an interface' in the orElse block.










share|improve this question




















  • 1





    Whats the error?

    – Nicholas K
    Nov 21 '18 at 16:13











  • Target type of a lambda expression must be an interface

    – arjun
    Nov 21 '18 at 16:17






  • 1





    Getting complex stream pipelines to compile can be tricky. There are some generally useful problem-solving techniques: 1) Add parameter types to all lambdas: (ArgType arg) -> .... 2) Add explicit type parameter to methods: <ArgType>.orElse(...). 3) Extract whole lambdas to local variables. The locals often look like this: Function<Arg1, Arg2> = ..., which makes it easy to set explicit type arguments. Applying these techniques often gives a more precise compilation error and help you find the problem. When the problem is fixed the helper types and variables can be removed.

    – Lii
    Nov 21 '18 at 16:23













  • What are the variables used in the code?

    – Mani
    Nov 21 '18 at 16:32






  • 2





    I'd recommend using a plain old if-else test on the result of recapPlacement.getAttId(). The Stream is fine, but the way you use Optional here violates its API notes, and the advice of its author. See The Mother of All Bikesheds for some ways to make your code readable.

    – erickson
    Nov 21 '18 at 17:15














3












3








3


1






I am trying to use a Stream in orElse and having difficulty in understanding the error.



collectorConfiguration = Optional.ofNullable(recapPlacement.getAttId())
.map(attId -> Optional.ofNullable(processorEngine.buildFrimFromAttId(attId))
.orElseThrow( () -> new OmegaException("UnableToFirmByAttId", recapPlacement.getAttId())))
.orElse( () -> Optional.ofNullable(collectorConfigurations.stream() //getting error here
.filter(cc -> recapPlacement.getPnetCode().equals(cc.getPnetCode()))
.filter(Objects::nonNull)
.findFirst())
.orElseThrow( () -> new OmegaException("CollectorCouldNotMapForPnetCode", recapPlacement.getPnetCode()))
);


Overall in the above code I am trying to




  1. get collectorConfig if attId is not null


  2. if attId is not null and collectorConfig not found for that attId then I am throwing exception


  3. if attId is null then I am using pnet code to get collectConfig by streaming collectConfigurations list


  4. if collectConfig is not found for pnetCode then I am throwing exception



It is giving a compilation error 'Target type of a lambda expression must be an interface' in the orElse block.










share|improve this question
















I am trying to use a Stream in orElse and having difficulty in understanding the error.



collectorConfiguration = Optional.ofNullable(recapPlacement.getAttId())
.map(attId -> Optional.ofNullable(processorEngine.buildFrimFromAttId(attId))
.orElseThrow( () -> new OmegaException("UnableToFirmByAttId", recapPlacement.getAttId())))
.orElse( () -> Optional.ofNullable(collectorConfigurations.stream() //getting error here
.filter(cc -> recapPlacement.getPnetCode().equals(cc.getPnetCode()))
.filter(Objects::nonNull)
.findFirst())
.orElseThrow( () -> new OmegaException("CollectorCouldNotMapForPnetCode", recapPlacement.getPnetCode()))
);


Overall in the above code I am trying to




  1. get collectorConfig if attId is not null


  2. if attId is not null and collectorConfig not found for that attId then I am throwing exception


  3. if attId is null then I am using pnet code to get collectConfig by streaming collectConfigurations list


  4. if collectConfig is not found for pnetCode then I am throwing exception



It is giving a compilation error 'Target type of a lambda expression must be an interface' in the orElse block.







java java-8 java-stream optional






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 17:00









nullpointer

47.9k11100194




47.9k11100194










asked Nov 21 '18 at 16:11









arjunarjun

13810




13810








  • 1





    Whats the error?

    – Nicholas K
    Nov 21 '18 at 16:13











  • Target type of a lambda expression must be an interface

    – arjun
    Nov 21 '18 at 16:17






  • 1





    Getting complex stream pipelines to compile can be tricky. There are some generally useful problem-solving techniques: 1) Add parameter types to all lambdas: (ArgType arg) -> .... 2) Add explicit type parameter to methods: <ArgType>.orElse(...). 3) Extract whole lambdas to local variables. The locals often look like this: Function<Arg1, Arg2> = ..., which makes it easy to set explicit type arguments. Applying these techniques often gives a more precise compilation error and help you find the problem. When the problem is fixed the helper types and variables can be removed.

    – Lii
    Nov 21 '18 at 16:23













  • What are the variables used in the code?

    – Mani
    Nov 21 '18 at 16:32






  • 2





    I'd recommend using a plain old if-else test on the result of recapPlacement.getAttId(). The Stream is fine, but the way you use Optional here violates its API notes, and the advice of its author. See The Mother of All Bikesheds for some ways to make your code readable.

    – erickson
    Nov 21 '18 at 17:15














  • 1





    Whats the error?

    – Nicholas K
    Nov 21 '18 at 16:13











  • Target type of a lambda expression must be an interface

    – arjun
    Nov 21 '18 at 16:17






  • 1





    Getting complex stream pipelines to compile can be tricky. There are some generally useful problem-solving techniques: 1) Add parameter types to all lambdas: (ArgType arg) -> .... 2) Add explicit type parameter to methods: <ArgType>.orElse(...). 3) Extract whole lambdas to local variables. The locals often look like this: Function<Arg1, Arg2> = ..., which makes it easy to set explicit type arguments. Applying these techniques often gives a more precise compilation error and help you find the problem. When the problem is fixed the helper types and variables can be removed.

    – Lii
    Nov 21 '18 at 16:23













  • What are the variables used in the code?

    – Mani
    Nov 21 '18 at 16:32






  • 2





    I'd recommend using a plain old if-else test on the result of recapPlacement.getAttId(). The Stream is fine, but the way you use Optional here violates its API notes, and the advice of its author. See The Mother of All Bikesheds for some ways to make your code readable.

    – erickson
    Nov 21 '18 at 17:15








1




1





Whats the error?

– Nicholas K
Nov 21 '18 at 16:13





Whats the error?

– Nicholas K
Nov 21 '18 at 16:13













Target type of a lambda expression must be an interface

– arjun
Nov 21 '18 at 16:17





Target type of a lambda expression must be an interface

– arjun
Nov 21 '18 at 16:17




1




1





Getting complex stream pipelines to compile can be tricky. There are some generally useful problem-solving techniques: 1) Add parameter types to all lambdas: (ArgType arg) -> .... 2) Add explicit type parameter to methods: <ArgType>.orElse(...). 3) Extract whole lambdas to local variables. The locals often look like this: Function<Arg1, Arg2> = ..., which makes it easy to set explicit type arguments. Applying these techniques often gives a more precise compilation error and help you find the problem. When the problem is fixed the helper types and variables can be removed.

– Lii
Nov 21 '18 at 16:23







Getting complex stream pipelines to compile can be tricky. There are some generally useful problem-solving techniques: 1) Add parameter types to all lambdas: (ArgType arg) -> .... 2) Add explicit type parameter to methods: <ArgType>.orElse(...). 3) Extract whole lambdas to local variables. The locals often look like this: Function<Arg1, Arg2> = ..., which makes it easy to set explicit type arguments. Applying these techniques often gives a more precise compilation error and help you find the problem. When the problem is fixed the helper types and variables can be removed.

– Lii
Nov 21 '18 at 16:23















What are the variables used in the code?

– Mani
Nov 21 '18 at 16:32





What are the variables used in the code?

– Mani
Nov 21 '18 at 16:32




2




2





I'd recommend using a plain old if-else test on the result of recapPlacement.getAttId(). The Stream is fine, but the way you use Optional here violates its API notes, and the advice of its author. See The Mother of All Bikesheds for some ways to make your code readable.

– erickson
Nov 21 '18 at 17:15





I'd recommend using a plain old if-else test on the result of recapPlacement.getAttId(). The Stream is fine, but the way you use Optional here violates its API notes, and the advice of its author. See The Mother of All Bikesheds for some ways to make your code readable.

– erickson
Nov 21 '18 at 17:15












2 Answers
2






active

oldest

votes


















4














You might want to replace



.orElse( () -> Optional.ofNullable(collectorConfigurations.stream() //getting error here


with Optional.orElseGet which expects a Supplier as :



.orElseGet( () -> Optional.ofNullable(collectorConfigurations.stream() ...




In addition to the above, you shouldn't need the Optional.ofNullable in the supplier



.orElseGet( () -> collectorConfigurations.stream()
.filter(cc -> recapPlacement.getPnetCode().equals(cc.getPnetCode()))
.filter(Objects::nonNull) //non-null filtered
.findFirst()) // optional
.orElseThrow( () -> new OmegaException("CollectorCouldNotMapForPnet...





share|improve this answer


























  • .OrElseGet() expecting a collector configuration but as I am using Optional() on it, it is throwing bad return type compilation error

    – arjun
    Nov 21 '18 at 16:43











  • Make sure you use the () -> as part of your .orElseGet(()->...).

    – YoYo
    Nov 21 '18 at 16:45













  • I am sure using it

    – arjun
    Nov 21 '18 at 16:47






  • 1





    Yeah that was a mistake. I thought I need optional to throw exception

    – arjun
    Nov 21 '18 at 16:52



















1














orElse takes a regular value, not anything that could be represented by a lambda. Simply removing the () -> should help. Alternatively, you might have meant to call orElseGet






share|improve this answer
























  • If I remove '() ->' then it will be Optional() which doesn't excepted by orElse

    – arjun
    Nov 21 '18 at 16:40











  • @arjun OK; we don't have enough code to infer the types expected here, but the entire wrapping in optionals seems unnecessary. Why do you wrap the result of a stream() call in optional? That will never return null.

    – OhleC
    Nov 21 '18 at 16:43











  • Sorry that was a mistake. I added it so that I can throw exception on that Optional().orElseThrow

    – arjun
    Nov 21 '18 at 16:46











  • Yeah that was the mistake. I thought I need optional to throw exception

    – arjun
    Nov 21 '18 at 16:52











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416163%2fstream-in-orelse-of-optional%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














You might want to replace



.orElse( () -> Optional.ofNullable(collectorConfigurations.stream() //getting error here


with Optional.orElseGet which expects a Supplier as :



.orElseGet( () -> Optional.ofNullable(collectorConfigurations.stream() ...




In addition to the above, you shouldn't need the Optional.ofNullable in the supplier



.orElseGet( () -> collectorConfigurations.stream()
.filter(cc -> recapPlacement.getPnetCode().equals(cc.getPnetCode()))
.filter(Objects::nonNull) //non-null filtered
.findFirst()) // optional
.orElseThrow( () -> new OmegaException("CollectorCouldNotMapForPnet...





share|improve this answer


























  • .OrElseGet() expecting a collector configuration but as I am using Optional() on it, it is throwing bad return type compilation error

    – arjun
    Nov 21 '18 at 16:43











  • Make sure you use the () -> as part of your .orElseGet(()->...).

    – YoYo
    Nov 21 '18 at 16:45













  • I am sure using it

    – arjun
    Nov 21 '18 at 16:47






  • 1





    Yeah that was a mistake. I thought I need optional to throw exception

    – arjun
    Nov 21 '18 at 16:52
















4














You might want to replace



.orElse( () -> Optional.ofNullable(collectorConfigurations.stream() //getting error here


with Optional.orElseGet which expects a Supplier as :



.orElseGet( () -> Optional.ofNullable(collectorConfigurations.stream() ...




In addition to the above, you shouldn't need the Optional.ofNullable in the supplier



.orElseGet( () -> collectorConfigurations.stream()
.filter(cc -> recapPlacement.getPnetCode().equals(cc.getPnetCode()))
.filter(Objects::nonNull) //non-null filtered
.findFirst()) // optional
.orElseThrow( () -> new OmegaException("CollectorCouldNotMapForPnet...





share|improve this answer


























  • .OrElseGet() expecting a collector configuration but as I am using Optional() on it, it is throwing bad return type compilation error

    – arjun
    Nov 21 '18 at 16:43











  • Make sure you use the () -> as part of your .orElseGet(()->...).

    – YoYo
    Nov 21 '18 at 16:45













  • I am sure using it

    – arjun
    Nov 21 '18 at 16:47






  • 1





    Yeah that was a mistake. I thought I need optional to throw exception

    – arjun
    Nov 21 '18 at 16:52














4












4








4







You might want to replace



.orElse( () -> Optional.ofNullable(collectorConfigurations.stream() //getting error here


with Optional.orElseGet which expects a Supplier as :



.orElseGet( () -> Optional.ofNullable(collectorConfigurations.stream() ...




In addition to the above, you shouldn't need the Optional.ofNullable in the supplier



.orElseGet( () -> collectorConfigurations.stream()
.filter(cc -> recapPlacement.getPnetCode().equals(cc.getPnetCode()))
.filter(Objects::nonNull) //non-null filtered
.findFirst()) // optional
.orElseThrow( () -> new OmegaException("CollectorCouldNotMapForPnet...





share|improve this answer















You might want to replace



.orElse( () -> Optional.ofNullable(collectorConfigurations.stream() //getting error here


with Optional.orElseGet which expects a Supplier as :



.orElseGet( () -> Optional.ofNullable(collectorConfigurations.stream() ...




In addition to the above, you shouldn't need the Optional.ofNullable in the supplier



.orElseGet( () -> collectorConfigurations.stream()
.filter(cc -> recapPlacement.getPnetCode().equals(cc.getPnetCode()))
.filter(Objects::nonNull) //non-null filtered
.findFirst()) // optional
.orElseThrow( () -> new OmegaException("CollectorCouldNotMapForPnet...






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 16:46

























answered Nov 21 '18 at 16:38









nullpointernullpointer

47.9k11100194




47.9k11100194













  • .OrElseGet() expecting a collector configuration but as I am using Optional() on it, it is throwing bad return type compilation error

    – arjun
    Nov 21 '18 at 16:43











  • Make sure you use the () -> as part of your .orElseGet(()->...).

    – YoYo
    Nov 21 '18 at 16:45













  • I am sure using it

    – arjun
    Nov 21 '18 at 16:47






  • 1





    Yeah that was a mistake. I thought I need optional to throw exception

    – arjun
    Nov 21 '18 at 16:52



















  • .OrElseGet() expecting a collector configuration but as I am using Optional() on it, it is throwing bad return type compilation error

    – arjun
    Nov 21 '18 at 16:43











  • Make sure you use the () -> as part of your .orElseGet(()->...).

    – YoYo
    Nov 21 '18 at 16:45













  • I am sure using it

    – arjun
    Nov 21 '18 at 16:47






  • 1





    Yeah that was a mistake. I thought I need optional to throw exception

    – arjun
    Nov 21 '18 at 16:52

















.OrElseGet() expecting a collector configuration but as I am using Optional() on it, it is throwing bad return type compilation error

– arjun
Nov 21 '18 at 16:43





.OrElseGet() expecting a collector configuration but as I am using Optional() on it, it is throwing bad return type compilation error

– arjun
Nov 21 '18 at 16:43













Make sure you use the () -> as part of your .orElseGet(()->...).

– YoYo
Nov 21 '18 at 16:45







Make sure you use the () -> as part of your .orElseGet(()->...).

– YoYo
Nov 21 '18 at 16:45















I am sure using it

– arjun
Nov 21 '18 at 16:47





I am sure using it

– arjun
Nov 21 '18 at 16:47




1




1





Yeah that was a mistake. I thought I need optional to throw exception

– arjun
Nov 21 '18 at 16:52





Yeah that was a mistake. I thought I need optional to throw exception

– arjun
Nov 21 '18 at 16:52













1














orElse takes a regular value, not anything that could be represented by a lambda. Simply removing the () -> should help. Alternatively, you might have meant to call orElseGet






share|improve this answer
























  • If I remove '() ->' then it will be Optional() which doesn't excepted by orElse

    – arjun
    Nov 21 '18 at 16:40











  • @arjun OK; we don't have enough code to infer the types expected here, but the entire wrapping in optionals seems unnecessary. Why do you wrap the result of a stream() call in optional? That will never return null.

    – OhleC
    Nov 21 '18 at 16:43











  • Sorry that was a mistake. I added it so that I can throw exception on that Optional().orElseThrow

    – arjun
    Nov 21 '18 at 16:46











  • Yeah that was the mistake. I thought I need optional to throw exception

    – arjun
    Nov 21 '18 at 16:52
















1














orElse takes a regular value, not anything that could be represented by a lambda. Simply removing the () -> should help. Alternatively, you might have meant to call orElseGet






share|improve this answer
























  • If I remove '() ->' then it will be Optional() which doesn't excepted by orElse

    – arjun
    Nov 21 '18 at 16:40











  • @arjun OK; we don't have enough code to infer the types expected here, but the entire wrapping in optionals seems unnecessary. Why do you wrap the result of a stream() call in optional? That will never return null.

    – OhleC
    Nov 21 '18 at 16:43











  • Sorry that was a mistake. I added it so that I can throw exception on that Optional().orElseThrow

    – arjun
    Nov 21 '18 at 16:46











  • Yeah that was the mistake. I thought I need optional to throw exception

    – arjun
    Nov 21 '18 at 16:52














1












1








1







orElse takes a regular value, not anything that could be represented by a lambda. Simply removing the () -> should help. Alternatively, you might have meant to call orElseGet






share|improve this answer













orElse takes a regular value, not anything that could be represented by a lambda. Simply removing the () -> should help. Alternatively, you might have meant to call orElseGet







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 16:36









OhleCOhleC

1,753717




1,753717













  • If I remove '() ->' then it will be Optional() which doesn't excepted by orElse

    – arjun
    Nov 21 '18 at 16:40











  • @arjun OK; we don't have enough code to infer the types expected here, but the entire wrapping in optionals seems unnecessary. Why do you wrap the result of a stream() call in optional? That will never return null.

    – OhleC
    Nov 21 '18 at 16:43











  • Sorry that was a mistake. I added it so that I can throw exception on that Optional().orElseThrow

    – arjun
    Nov 21 '18 at 16:46











  • Yeah that was the mistake. I thought I need optional to throw exception

    – arjun
    Nov 21 '18 at 16:52



















  • If I remove '() ->' then it will be Optional() which doesn't excepted by orElse

    – arjun
    Nov 21 '18 at 16:40











  • @arjun OK; we don't have enough code to infer the types expected here, but the entire wrapping in optionals seems unnecessary. Why do you wrap the result of a stream() call in optional? That will never return null.

    – OhleC
    Nov 21 '18 at 16:43











  • Sorry that was a mistake. I added it so that I can throw exception on that Optional().orElseThrow

    – arjun
    Nov 21 '18 at 16:46











  • Yeah that was the mistake. I thought I need optional to throw exception

    – arjun
    Nov 21 '18 at 16:52

















If I remove '() ->' then it will be Optional() which doesn't excepted by orElse

– arjun
Nov 21 '18 at 16:40





If I remove '() ->' then it will be Optional() which doesn't excepted by orElse

– arjun
Nov 21 '18 at 16:40













@arjun OK; we don't have enough code to infer the types expected here, but the entire wrapping in optionals seems unnecessary. Why do you wrap the result of a stream() call in optional? That will never return null.

– OhleC
Nov 21 '18 at 16:43





@arjun OK; we don't have enough code to infer the types expected here, but the entire wrapping in optionals seems unnecessary. Why do you wrap the result of a stream() call in optional? That will never return null.

– OhleC
Nov 21 '18 at 16:43













Sorry that was a mistake. I added it so that I can throw exception on that Optional().orElseThrow

– arjun
Nov 21 '18 at 16:46





Sorry that was a mistake. I added it so that I can throw exception on that Optional().orElseThrow

– arjun
Nov 21 '18 at 16:46













Yeah that was the mistake. I thought I need optional to throw exception

– arjun
Nov 21 '18 at 16:52





Yeah that was the mistake. I thought I need optional to throw exception

– arjun
Nov 21 '18 at 16:52


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416163%2fstream-in-orelse-of-optional%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?