Skip to main content

All Questions

Tagged with
-2 votes
0 answers
37 views

Why Java shows strange characters when print a OptionalDouble? [duplicate]

I declared a OptionalDouble vector, and when the program print this give me strange characters instead of the vector values: [[Ljava.util.OptionalDouble;@37bba4006. [[Ljava.util.OptionalDouble;@...
Bujakiewicz Franco's user avatar
0 votes
1 answer
92 views

Optional's orElse() executed even when object is present [duplicate]

I've encountered an unexpected behavior while using the Optional API in Java. Session session = sessionService .getSessionById(id) .orElse( ...
Souhaib's user avatar
  • 119
1 vote
0 answers
22 views

Why Optional lambda replace with method reference Causing NullPointerException [duplicate]

There is a A Class class A { private String str; public void setStr(String str) { this.str = str; } } this method works fine; public static void main(String[] args) { ...
周亿进's user avatar
-1 votes
1 answer
122 views

Generate a type from a Java DTO type with many fields being null and have all getters as Optional<T>

I am currently working with a Java DTO class (written by others) that has almost 300 fields where many of these end up being null. What I see in the codebase are lots of null checks and more recently ...
Leon's user avatar
  • 528
0 votes
3 answers
71 views

Springboot: How to get an entity optional property and check null?

I have a service in Springboot and I want to get an optional entity and to check if is not null to do something after. User repository class public interface UserRepository extends JpaRepository<...
obela06's user avatar
  • 325
2 votes
2 answers
116 views

Optional.ifPresent throws NPE when action is null AND optional not present

Why does this throw a NullPointerException? The docs for Java 8 state that: "If a value is present, invoke the specified consumer with the value, otherwise do nothing." public static ...
pecks's user avatar
  • 340
2 votes
2 answers
82 views

Monad Map with two values in Java Functional Programming

Forgive me if this is a basic question in FP. Let's consider Optional monad. I know I can use map to transform an Optional to another Optional based on a function (which will be called if optional has ...
Mahdi's user avatar
  • 2,197
0 votes
1 answer
56 views

Optional and complete method

How to work correctly with Optional if I need to complete a method (with some actions, log for example) in case of an empty Optional? Otherwise, get the object from Optional and continue working I ...
Aliaksei's user avatar
  • 1,417
5 votes
1 answer
95 views

In Frege how can I convert an String safely to a Maybe Int?

In Frege I want to convert an String to an Int, but need to handle unparsable strings too. So I guess I'm looking for something like a readMaybe function. Where do I find this? Or how can I use Java's ...
halloleo's user avatar
  • 9,924
0 votes
1 answer
122 views

Is there a recommended idiomatic way to adapt a Java Optional to a Kotlin nullable?

I am writing Kotlin code that uses a Java library which uses Optionals, and I would prefer to use Kotlin's nullable idiom in Kotlin-world. For example, my library may have a function Optional<Foo&...
Vihung's user avatar
  • 13.3k
0 votes
3 answers
118 views

Cannot Stream average() undefined for OptionalDouble

I'm using this code but eclipse shows an error saying stream() is undefined for the type OptionalDouble The error shown by eclipse is The method stream() is undefined for the type OptionalDouble . ...
nvn's user avatar
  • 159
1 vote
2 answers
160 views

Chaining Optional and Stream in Java(preferably 11)

I have a list of Foo objects, where each Foo contains a name and a List<Strings>. I am trying to find if the fooList contains a Foo object with a target name, and if such element exists, find ...
de5tro's user avatar
  • 33
0 votes
0 answers
108 views

Does using java.util.Optional affect memory/speed and how does JIT Compiler handle it?

I've been using java.util.Optional extensively in my code for better null handling. I even went as far as creating new "safe" datastructures with stuff like: public Optional<Integer> ...
xtay2's user avatar
  • 607
1 vote
3 answers
263 views

guard/if let in Java - declare a property or an object if it can be unwrapped

In swift there is the guard let / if let pattern allowing us to declare an object or a property only if it can be unwrapped. it works a follow: func getMeaningOfLife() -> Int? { 42 } func ...
Cublax's user avatar
  • 1,349
0 votes
3 answers
112 views

How best to populate a variable using Optional?

I'm using an optional ID here but I don't like having to declare TWO variables to receive the data. What is a more concise way to accomplish this without having to declare an extra OptionalOrg ...
dataman's user avatar
  • 125

15 30 50 per page
1
2 3 4 5
74