Stream in orElse of optional
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
get
collectorConfig
ifattId
is not nullif
attId
is not null andcollectorConfig
not found for thatattId
then I am throwing exceptionif
attId
is null then I am usingpnet
code to getcollectConfig
by streamingcollectConfigurations
listif
collectConfig
is not found forpnetCode
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
add a comment |
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
get
collectorConfig
ifattId
is not nullif
attId
is not null andcollectorConfig
not found for thatattId
then I am throwing exceptionif
attId
is null then I am usingpnet
code to getcollectConfig
by streamingcollectConfigurations
listif
collectConfig
is not found forpnetCode
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
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 ofrecapPlacement.getAttId()
. TheStream
is fine, but the way you useOptional
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
add a comment |
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
get
collectorConfig
ifattId
is not nullif
attId
is not null andcollectorConfig
not found for thatattId
then I am throwing exceptionif
attId
is null then I am usingpnet
code to getcollectConfig
by streamingcollectConfigurations
listif
collectConfig
is not found forpnetCode
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
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
get
collectorConfig
ifattId
is not nullif
attId
is not null andcollectorConfig
not found for thatattId
then I am throwing exceptionif
attId
is null then I am usingpnet
code to getcollectConfig
by streamingcollectConfigurations
listif
collectConfig
is not found forpnetCode
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
java java-8 java-stream optional
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 ofrecapPlacement.getAttId()
. TheStream
is fine, but the way you useOptional
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
add a comment |
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 ofrecapPlacement.getAttId()
. TheStream
is fine, but the way you useOptional
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
add a comment |
2 Answers
2
active
oldest
votes
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...
.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
add a comment |
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
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 astream()
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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...
.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
add a comment |
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...
.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
add a comment |
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...
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...
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
add a comment |
.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
add a comment |
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
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 astream()
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
add a comment |
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
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 astream()
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
add a comment |
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
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
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 astream()
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
add a comment |
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 astream()
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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()
. TheStream
is fine, but the way you useOptional
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