Why does Optional.map make this assignment work?Stream.findFirst different than Optional.of?Does a finally block always get executed in Java?How does the Java 'for each' loop work?What is a serialVersionUID and why should I use it?Why does Java have transient fields?Why is subtracting these two times (in 1927) giving a strange result?Why don't Java's +=, -=, *=, /= compound assignment operators require casting?Why is char[] preferred over String for passwords?Why is it faster to process a sorted array than an unsorted array?Why does this code using random strings print “hello world”?Why is printing “B” dramatically slower than printing “#”?

Chess with symmetric move-square

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?

New order #4: World

Why are 150k or 200k jobs considered good when there are 300k+ births a month?

A function which translates a sentence to title-case

How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?

How to add power-LED to my small amplifier?

How is it possible for user's password to be changed after storage was encrypted? (on OS X, Android)

Why don't electron-positron collisions release infinite energy?

whey we use polarized capacitor?

How can bays and straits be determined in a procedurally generated map?

Japan - Plan around max visa duration

"You are your self first supporter", a more proper way to say it

Schwarzchild Radius of the Universe

Download, install and reboot computer at night if needed

Copycat chess is back

Pronouncing Dictionary.com's W.O.D "vade mecum" in English

What typically incentivizes a professor to change jobs to a lower ranking university?

I see my dog run

What is the offset in a seaplane's hull?

Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)

What are these boxed doors outside store fronts in New York?



Why does Optional.map make this assignment work?


Stream.findFirst different than Optional.of?Does a finally block always get executed in Java?How does the Java 'for each' loop work?What is a serialVersionUID and why should I use it?Why does Java have transient fields?Why is subtracting these two times (in 1927) giving a strange result?Why don't Java's +=, -=, *=, /= compound assignment operators require casting?Why is char[] preferred over String for passwords?Why is it faster to process a sorted array than an unsorted array?Why does this code using random strings print “hello world”?Why is printing “B” dramatically slower than printing “#”?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








27















Optional<ArrayList<String>> option = Optional.of(new ArrayList<>());

Optional<ArrayList<?>> doesntWork = option;

Optional<ArrayList<?>> works = option.map(list -> list);


The first attempted assignment does not compile, but the second one with the map does. It feels like the map shouldn't actually accomplish anything, but for some reason it turns my Optional<ArrayList<String>> into an Optional<ArrayList<?>>. Is there some sort of implicit cast going on?










share|improve this question






























    27















    Optional<ArrayList<String>> option = Optional.of(new ArrayList<>());

    Optional<ArrayList<?>> doesntWork = option;

    Optional<ArrayList<?>> works = option.map(list -> list);


    The first attempted assignment does not compile, but the second one with the map does. It feels like the map shouldn't actually accomplish anything, but for some reason it turns my Optional<ArrayList<String>> into an Optional<ArrayList<?>>. Is there some sort of implicit cast going on?










    share|improve this question


























      27












      27








      27


      4






      Optional<ArrayList<String>> option = Optional.of(new ArrayList<>());

      Optional<ArrayList<?>> doesntWork = option;

      Optional<ArrayList<?>> works = option.map(list -> list);


      The first attempted assignment does not compile, but the second one with the map does. It feels like the map shouldn't actually accomplish anything, but for some reason it turns my Optional<ArrayList<String>> into an Optional<ArrayList<?>>. Is there some sort of implicit cast going on?










      share|improve this question
















      Optional<ArrayList<String>> option = Optional.of(new ArrayList<>());

      Optional<ArrayList<?>> doesntWork = option;

      Optional<ArrayList<?>> works = option.map(list -> list);


      The first attempted assignment does not compile, but the second one with the map does. It feels like the map shouldn't actually accomplish anything, but for some reason it turns my Optional<ArrayList<String>> into an Optional<ArrayList<?>>. Is there some sort of implicit cast going on?







      java generics java-8 optional






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 4 at 8:29









      Eran

      292k37481564




      292k37481564










      asked Apr 4 at 8:12









      Carl MindenCarl Minden

      388318




      388318






















          4 Answers
          4






          active

          oldest

          votes


















          17














          If you look into the code of map and follow all the method calls, you'll see that option.map(list -> list) ends up returning new Optional<>(option.get()). So you can replace your last assignment with:



          Optional<ArrayList<?>> works = new Optional<>(option.get());


          This creates a new Optional<ArrayList<?>> and initializes its value instance variable (whose type is ArrayList<?>) with the ArrayList<String> returned by map.get(). This is a valid assignment.




          Is there some sort of implicit cast going on?




          No, map returns a new Optional instance. It doesn't cast the original instance on which it was called.



          Here's the chain of method calls:



          option.map(list -> list)


          returns (since option is not empty)



          Optional.ofNullable(mapper.apply(value))


          which in your case is the same as



          Optional.ofNullable(value)


          which returns (since the value is not null):



          Optional.of(value)


          which returns



          new Optional<>(value)





          share|improve this answer

























          • Interesting, it just seems so strange that .map(list -> list) would do something, but yeah I suppose that makes sense.

            – Carl Minden
            Apr 4 at 8:26






          • 3





            See also this answer. Its last code example uses map(Function.identity()) where a direct assignment of the Optional is not possible. In the context of this question, A would ArrayList<?> and B would be ArrayList<String>.

            – Holger
            Apr 4 at 10:31



















          7














          Well the first one does not work because generics are invariant, the only way to make them covariant is to add a bounded type for example:



           Optional<? extends ArrayList<String>> doesntWork = option; 


          that would compile.



          And when you say that the map step should no accomplish anything is well, not correct. Look at the definition of Optional::map:



          public <U> Optional<U> map(Function<? super T, ? extends U> mapper) 
          Objects.requireNonNull(mapper);
          if (!isPresent())
          return empty();
          else
          return Optional.ofNullable(mapper.apply(value));




          roughly speaking it does transform from Optional<T> to Optional<U>...






          share|improve this answer






























            0














            Your option.map has the signature



            <ArrayList<?>> Optional<ArrayList<?>> java.util.Optional.map(Function<? super ArrayList<String>, ? extends ArrayList<?>> mapper)


            So this



            Optional<? extends ArrayList<?>> doesntWork = option;


            does compile.






            share|improve this answer























            • Yeah, that does compile, but I am more interested in why the map fixes it, this is just a simplistic version of what I am actually trying to do. In my actual code I am overriding a method that needs to return the equivalent of the Optional<ArrayList<?>> so just changing the type of that assignment doesn't really help.

              – Carl Minden
              Apr 4 at 8:22


















            0














            In your latter case the return type of the Optional.map method is implicitly determined by the type of your works variable. That's why there is a difference.






            share|improve this answer























            • But how is that different from the first assignment? if the signature of map is determined to by the type declaration of the assignment to return Optional<ArrayList<?>> then that means the return of the lambda would be of the type ArrayList<?> and since my lambda is (at least as far as I can tell) returning the concrete type ArrayList<String> something somewhere is casting it after the fact I guess?

              – Carl Minden
              Apr 4 at 8:24











            • Yes, exactly. The difference is that the type of option is static where the return type of Optional.map is dynamically determined by the to be assigned variable.

              – dpr
              Apr 4 at 8:42











            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%2f55510951%2fwhy-does-optional-map-make-this-assignment-work%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            17














            If you look into the code of map and follow all the method calls, you'll see that option.map(list -> list) ends up returning new Optional<>(option.get()). So you can replace your last assignment with:



            Optional<ArrayList<?>> works = new Optional<>(option.get());


            This creates a new Optional<ArrayList<?>> and initializes its value instance variable (whose type is ArrayList<?>) with the ArrayList<String> returned by map.get(). This is a valid assignment.




            Is there some sort of implicit cast going on?




            No, map returns a new Optional instance. It doesn't cast the original instance on which it was called.



            Here's the chain of method calls:



            option.map(list -> list)


            returns (since option is not empty)



            Optional.ofNullable(mapper.apply(value))


            which in your case is the same as



            Optional.ofNullable(value)


            which returns (since the value is not null):



            Optional.of(value)


            which returns



            new Optional<>(value)





            share|improve this answer

























            • Interesting, it just seems so strange that .map(list -> list) would do something, but yeah I suppose that makes sense.

              – Carl Minden
              Apr 4 at 8:26






            • 3





              See also this answer. Its last code example uses map(Function.identity()) where a direct assignment of the Optional is not possible. In the context of this question, A would ArrayList<?> and B would be ArrayList<String>.

              – Holger
              Apr 4 at 10:31
















            17














            If you look into the code of map and follow all the method calls, you'll see that option.map(list -> list) ends up returning new Optional<>(option.get()). So you can replace your last assignment with:



            Optional<ArrayList<?>> works = new Optional<>(option.get());


            This creates a new Optional<ArrayList<?>> and initializes its value instance variable (whose type is ArrayList<?>) with the ArrayList<String> returned by map.get(). This is a valid assignment.




            Is there some sort of implicit cast going on?




            No, map returns a new Optional instance. It doesn't cast the original instance on which it was called.



            Here's the chain of method calls:



            option.map(list -> list)


            returns (since option is not empty)



            Optional.ofNullable(mapper.apply(value))


            which in your case is the same as



            Optional.ofNullable(value)


            which returns (since the value is not null):



            Optional.of(value)


            which returns



            new Optional<>(value)





            share|improve this answer

























            • Interesting, it just seems so strange that .map(list -> list) would do something, but yeah I suppose that makes sense.

              – Carl Minden
              Apr 4 at 8:26






            • 3





              See also this answer. Its last code example uses map(Function.identity()) where a direct assignment of the Optional is not possible. In the context of this question, A would ArrayList<?> and B would be ArrayList<String>.

              – Holger
              Apr 4 at 10:31














            17












            17








            17







            If you look into the code of map and follow all the method calls, you'll see that option.map(list -> list) ends up returning new Optional<>(option.get()). So you can replace your last assignment with:



            Optional<ArrayList<?>> works = new Optional<>(option.get());


            This creates a new Optional<ArrayList<?>> and initializes its value instance variable (whose type is ArrayList<?>) with the ArrayList<String> returned by map.get(). This is a valid assignment.




            Is there some sort of implicit cast going on?




            No, map returns a new Optional instance. It doesn't cast the original instance on which it was called.



            Here's the chain of method calls:



            option.map(list -> list)


            returns (since option is not empty)



            Optional.ofNullable(mapper.apply(value))


            which in your case is the same as



            Optional.ofNullable(value)


            which returns (since the value is not null):



            Optional.of(value)


            which returns



            new Optional<>(value)





            share|improve this answer















            If you look into the code of map and follow all the method calls, you'll see that option.map(list -> list) ends up returning new Optional<>(option.get()). So you can replace your last assignment with:



            Optional<ArrayList<?>> works = new Optional<>(option.get());


            This creates a new Optional<ArrayList<?>> and initializes its value instance variable (whose type is ArrayList<?>) with the ArrayList<String> returned by map.get(). This is a valid assignment.




            Is there some sort of implicit cast going on?




            No, map returns a new Optional instance. It doesn't cast the original instance on which it was called.



            Here's the chain of method calls:



            option.map(list -> list)


            returns (since option is not empty)



            Optional.ofNullable(mapper.apply(value))


            which in your case is the same as



            Optional.ofNullable(value)


            which returns (since the value is not null):



            Optional.of(value)


            which returns



            new Optional<>(value)






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 2 days ago

























            answered Apr 4 at 8:23









            EranEran

            292k37481564




            292k37481564












            • Interesting, it just seems so strange that .map(list -> list) would do something, but yeah I suppose that makes sense.

              – Carl Minden
              Apr 4 at 8:26






            • 3





              See also this answer. Its last code example uses map(Function.identity()) where a direct assignment of the Optional is not possible. In the context of this question, A would ArrayList<?> and B would be ArrayList<String>.

              – Holger
              Apr 4 at 10:31


















            • Interesting, it just seems so strange that .map(list -> list) would do something, but yeah I suppose that makes sense.

              – Carl Minden
              Apr 4 at 8:26






            • 3





              See also this answer. Its last code example uses map(Function.identity()) where a direct assignment of the Optional is not possible. In the context of this question, A would ArrayList<?> and B would be ArrayList<String>.

              – Holger
              Apr 4 at 10:31

















            Interesting, it just seems so strange that .map(list -> list) would do something, but yeah I suppose that makes sense.

            – Carl Minden
            Apr 4 at 8:26





            Interesting, it just seems so strange that .map(list -> list) would do something, but yeah I suppose that makes sense.

            – Carl Minden
            Apr 4 at 8:26




            3




            3





            See also this answer. Its last code example uses map(Function.identity()) where a direct assignment of the Optional is not possible. In the context of this question, A would ArrayList<?> and B would be ArrayList<String>.

            – Holger
            Apr 4 at 10:31






            See also this answer. Its last code example uses map(Function.identity()) where a direct assignment of the Optional is not possible. In the context of this question, A would ArrayList<?> and B would be ArrayList<String>.

            – Holger
            Apr 4 at 10:31














            7














            Well the first one does not work because generics are invariant, the only way to make them covariant is to add a bounded type for example:



             Optional<? extends ArrayList<String>> doesntWork = option; 


            that would compile.



            And when you say that the map step should no accomplish anything is well, not correct. Look at the definition of Optional::map:



            public <U> Optional<U> map(Function<? super T, ? extends U> mapper) 
            Objects.requireNonNull(mapper);
            if (!isPresent())
            return empty();
            else
            return Optional.ofNullable(mapper.apply(value));




            roughly speaking it does transform from Optional<T> to Optional<U>...






            share|improve this answer



























              7














              Well the first one does not work because generics are invariant, the only way to make them covariant is to add a bounded type for example:



               Optional<? extends ArrayList<String>> doesntWork = option; 


              that would compile.



              And when you say that the map step should no accomplish anything is well, not correct. Look at the definition of Optional::map:



              public <U> Optional<U> map(Function<? super T, ? extends U> mapper) 
              Objects.requireNonNull(mapper);
              if (!isPresent())
              return empty();
              else
              return Optional.ofNullable(mapper.apply(value));




              roughly speaking it does transform from Optional<T> to Optional<U>...






              share|improve this answer

























                7












                7








                7







                Well the first one does not work because generics are invariant, the only way to make them covariant is to add a bounded type for example:



                 Optional<? extends ArrayList<String>> doesntWork = option; 


                that would compile.



                And when you say that the map step should no accomplish anything is well, not correct. Look at the definition of Optional::map:



                public <U> Optional<U> map(Function<? super T, ? extends U> mapper) 
                Objects.requireNonNull(mapper);
                if (!isPresent())
                return empty();
                else
                return Optional.ofNullable(mapper.apply(value));




                roughly speaking it does transform from Optional<T> to Optional<U>...






                share|improve this answer













                Well the first one does not work because generics are invariant, the only way to make them covariant is to add a bounded type for example:



                 Optional<? extends ArrayList<String>> doesntWork = option; 


                that would compile.



                And when you say that the map step should no accomplish anything is well, not correct. Look at the definition of Optional::map:



                public <U> Optional<U> map(Function<? super T, ? extends U> mapper) 
                Objects.requireNonNull(mapper);
                if (!isPresent())
                return empty();
                else
                return Optional.ofNullable(mapper.apply(value));




                roughly speaking it does transform from Optional<T> to Optional<U>...







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 4 at 9:15









                EugeneEugene

                72.3k9103172




                72.3k9103172





















                    0














                    Your option.map has the signature



                    <ArrayList<?>> Optional<ArrayList<?>> java.util.Optional.map(Function<? super ArrayList<String>, ? extends ArrayList<?>> mapper)


                    So this



                    Optional<? extends ArrayList<?>> doesntWork = option;


                    does compile.






                    share|improve this answer























                    • Yeah, that does compile, but I am more interested in why the map fixes it, this is just a simplistic version of what I am actually trying to do. In my actual code I am overriding a method that needs to return the equivalent of the Optional<ArrayList<?>> so just changing the type of that assignment doesn't really help.

                      – Carl Minden
                      Apr 4 at 8:22















                    0














                    Your option.map has the signature



                    <ArrayList<?>> Optional<ArrayList<?>> java.util.Optional.map(Function<? super ArrayList<String>, ? extends ArrayList<?>> mapper)


                    So this



                    Optional<? extends ArrayList<?>> doesntWork = option;


                    does compile.






                    share|improve this answer























                    • Yeah, that does compile, but I am more interested in why the map fixes it, this is just a simplistic version of what I am actually trying to do. In my actual code I am overriding a method that needs to return the equivalent of the Optional<ArrayList<?>> so just changing the type of that assignment doesn't really help.

                      – Carl Minden
                      Apr 4 at 8:22













                    0












                    0








                    0







                    Your option.map has the signature



                    <ArrayList<?>> Optional<ArrayList<?>> java.util.Optional.map(Function<? super ArrayList<String>, ? extends ArrayList<?>> mapper)


                    So this



                    Optional<? extends ArrayList<?>> doesntWork = option;


                    does compile.






                    share|improve this answer













                    Your option.map has the signature



                    <ArrayList<?>> Optional<ArrayList<?>> java.util.Optional.map(Function<? super ArrayList<String>, ? extends ArrayList<?>> mapper)


                    So this



                    Optional<? extends ArrayList<?>> doesntWork = option;


                    does compile.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 4 at 8:17









                    Lutz HornLutz Horn

                    65812




                    65812












                    • Yeah, that does compile, but I am more interested in why the map fixes it, this is just a simplistic version of what I am actually trying to do. In my actual code I am overriding a method that needs to return the equivalent of the Optional<ArrayList<?>> so just changing the type of that assignment doesn't really help.

                      – Carl Minden
                      Apr 4 at 8:22

















                    • Yeah, that does compile, but I am more interested in why the map fixes it, this is just a simplistic version of what I am actually trying to do. In my actual code I am overriding a method that needs to return the equivalent of the Optional<ArrayList<?>> so just changing the type of that assignment doesn't really help.

                      – Carl Minden
                      Apr 4 at 8:22
















                    Yeah, that does compile, but I am more interested in why the map fixes it, this is just a simplistic version of what I am actually trying to do. In my actual code I am overriding a method that needs to return the equivalent of the Optional<ArrayList<?>> so just changing the type of that assignment doesn't really help.

                    – Carl Minden
                    Apr 4 at 8:22





                    Yeah, that does compile, but I am more interested in why the map fixes it, this is just a simplistic version of what I am actually trying to do. In my actual code I am overriding a method that needs to return the equivalent of the Optional<ArrayList<?>> so just changing the type of that assignment doesn't really help.

                    – Carl Minden
                    Apr 4 at 8:22











                    0














                    In your latter case the return type of the Optional.map method is implicitly determined by the type of your works variable. That's why there is a difference.






                    share|improve this answer























                    • But how is that different from the first assignment? if the signature of map is determined to by the type declaration of the assignment to return Optional<ArrayList<?>> then that means the return of the lambda would be of the type ArrayList<?> and since my lambda is (at least as far as I can tell) returning the concrete type ArrayList<String> something somewhere is casting it after the fact I guess?

                      – Carl Minden
                      Apr 4 at 8:24











                    • Yes, exactly. The difference is that the type of option is static where the return type of Optional.map is dynamically determined by the to be assigned variable.

                      – dpr
                      Apr 4 at 8:42















                    0














                    In your latter case the return type of the Optional.map method is implicitly determined by the type of your works variable. That's why there is a difference.






                    share|improve this answer























                    • But how is that different from the first assignment? if the signature of map is determined to by the type declaration of the assignment to return Optional<ArrayList<?>> then that means the return of the lambda would be of the type ArrayList<?> and since my lambda is (at least as far as I can tell) returning the concrete type ArrayList<String> something somewhere is casting it after the fact I guess?

                      – Carl Minden
                      Apr 4 at 8:24











                    • Yes, exactly. The difference is that the type of option is static where the return type of Optional.map is dynamically determined by the to be assigned variable.

                      – dpr
                      Apr 4 at 8:42













                    0












                    0








                    0







                    In your latter case the return type of the Optional.map method is implicitly determined by the type of your works variable. That's why there is a difference.






                    share|improve this answer













                    In your latter case the return type of the Optional.map method is implicitly determined by the type of your works variable. That's why there is a difference.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 4 at 8:18









                    dprdpr

                    4,97311647




                    4,97311647












                    • But how is that different from the first assignment? if the signature of map is determined to by the type declaration of the assignment to return Optional<ArrayList<?>> then that means the return of the lambda would be of the type ArrayList<?> and since my lambda is (at least as far as I can tell) returning the concrete type ArrayList<String> something somewhere is casting it after the fact I guess?

                      – Carl Minden
                      Apr 4 at 8:24











                    • Yes, exactly. The difference is that the type of option is static where the return type of Optional.map is dynamically determined by the to be assigned variable.

                      – dpr
                      Apr 4 at 8:42

















                    • But how is that different from the first assignment? if the signature of map is determined to by the type declaration of the assignment to return Optional<ArrayList<?>> then that means the return of the lambda would be of the type ArrayList<?> and since my lambda is (at least as far as I can tell) returning the concrete type ArrayList<String> something somewhere is casting it after the fact I guess?

                      – Carl Minden
                      Apr 4 at 8:24











                    • Yes, exactly. The difference is that the type of option is static where the return type of Optional.map is dynamically determined by the to be assigned variable.

                      – dpr
                      Apr 4 at 8:42
















                    But how is that different from the first assignment? if the signature of map is determined to by the type declaration of the assignment to return Optional<ArrayList<?>> then that means the return of the lambda would be of the type ArrayList<?> and since my lambda is (at least as far as I can tell) returning the concrete type ArrayList<String> something somewhere is casting it after the fact I guess?

                    – Carl Minden
                    Apr 4 at 8:24





                    But how is that different from the first assignment? if the signature of map is determined to by the type declaration of the assignment to return Optional<ArrayList<?>> then that means the return of the lambda would be of the type ArrayList<?> and since my lambda is (at least as far as I can tell) returning the concrete type ArrayList<String> something somewhere is casting it after the fact I guess?

                    – Carl Minden
                    Apr 4 at 8:24













                    Yes, exactly. The difference is that the type of option is static where the return type of Optional.map is dynamically determined by the to be assigned variable.

                    – dpr
                    Apr 4 at 8:42





                    Yes, exactly. The difference is that the type of option is static where the return type of Optional.map is dynamically determined by the to be assigned variable.

                    – dpr
                    Apr 4 at 8:42

















                    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%2f55510951%2fwhy-does-optional-map-make-this-assignment-work%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

                    Distance measures on a map of a game The 2019 Stack Overflow Developer Survey Results Are Inmin distance in a graphShortest distance path on contour plotHow to plot a tilted map?Finding points outside of a diskDelaunay link distanceAnnulus from GeoDisks: drawing a ring on a mapNegative Correlation DistanceFind distance along a path (GPS coordinates)Finding position at given distance in a GeoPathMathematics behind distance estimation using camera

                    How to get a smooth, uniform ParametricPlot of a 2D Region?How to plot a complicated Region?How to exclude a region from ParametricPlotHow discretize a region placing vertices on a specific non-uniform gridHow to transform a Plot or a ParametricPlot into a RegionHow can I get a smooth plot of a bounded region?Smooth ParametricPlot3D with RegionFunction?Smooth border of a region ParametricPlotSmooth region boundarySmooth region plot from list of pointsGet minimum y of a certain x in a region

                    Genealogie vun de Merowenger Vum Merowech bis zum Chilperich I. | Navigatiounsmenü