You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by keeganwitt <gi...@git.apache.org> on 2015/08/21 06:55:51 UTC

[GitHub] incubator-groovy pull request: Document primitive autowrapping

GitHub user keeganwitt opened a pull request:

    https://github.com/apache/incubator-groovy/pull/94

    Document primitive autowrapping

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/keeganwitt/incubator-groovy doc-primitives

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-groovy/pull/94.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #94
    
----
commit 4de0b6176142c63581f3807ba794db795e89bd87
Author: Keegan Witt <ke...@gmail.com>
Date:   2015-08-21T04:51:35Z

    document primitive autowrapping

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-groovy pull request: Document primitive autowrapping

Posted by keeganwitt <gi...@git.apache.org>.
Github user keeganwitt commented on a diff in the pull request:

    https://github.com/apache/incubator-groovy/pull/94#discussion_r37699872
  
    --- Diff: src/spec/doc/core-differences-java.adoc ---
    @@ -260,6 +260,19 @@ with exception.
     include::{projectdir}/src/spec/test/DifferencesFromJavaTest.groovy[tags=chars_c_vs_groovy_cast,indent=0]
     ----
     
    +== Primitives and wrappers
    +
    +Because uses Objects for everything, it link:core-object-orientation.html#_primitive_types[autowraps] references
    --- End diff --
    
    Oops. Yes I did, thank you.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-groovy pull request: Document primitive autowrapping

Posted by shils <gi...@git.apache.org>.
Github user shils commented on a diff in the pull request:

    https://github.com/apache/incubator-groovy/pull/94#discussion_r37697087
  
    --- Diff: src/spec/doc/core-differences-java.adoc ---
    @@ -260,6 +260,19 @@ with exception.
     include::{projectdir}/src/spec/test/DifferencesFromJavaTest.groovy[tags=chars_c_vs_groovy_cast,indent=0]
     ----
     
    +== Primitives and wrappers
    +
    +Because uses Objects for everything, it link:core-object-orientation.html#_primitive_types[autowraps] references
    --- End diff --
    
    Did you mean 'Because Groovy uses Objects for everything..' ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-groovy pull request: Document primitive autowrapping

Posted by keeganwitt <gi...@git.apache.org>.
Github user keeganwitt commented on a diff in the pull request:

    https://github.com/apache/incubator-groovy/pull/94#discussion_r37699868
  
    --- Diff: src/spec/doc/core-object-orientation.adoc ---
    @@ -35,6 +35,51 @@ Groovy supports the same primitive types as those defined by the {jls}[Java Lang
     * `boolean` type (exactly `true` or `false`)
     * `char` type (16 bit, usable as a numeric type, representing an UTF-16 code)
     
    +While Groovy declares and stores primitive fields and variables as primitives, because it uses Objects for
    +everything, it autowraps references to primitives. Just like Java, the wrappers it uses are
    +
    +[cols="1,1" options="header"]
    +.primitive wrappers
    +|====
    +| Primitive type
    +| Wrapper class
    +
    +| boolean
    +| Boolean
    +
    +| char
    +| Character
    +
    +| short
    +| Short
    +
    +| int
    +| Integer
    +
    +| long
    +| Long
    +
    +| float
    +| Float
    +
    +| double
    +| Double
    +|====
    +
    +Here's an example using `int`
    +
    +[source,groovy]
    +----
    +include::{projectdir}/src/spec/test/PrimitiveTest.groovy[tags=primitive_references,indent=0]
    +----
    +
    +Now you may be concerned that this means every time you use a mathematical operator on a reference to a primitive
    +that you'll incur the cost of unboxing and reboxing the primitive. But this is not the case, as Groovy will compile
    +your operators into their link:core-operators.html#_operator-overloading[method equivalents] and uses those instead.
    +Additionally, Groovy will automatically unbox to a primitive when calling Java that takes a primitive parameter and
    --- End diff --
    
    Yes, that is what I meant.  I'll make this change.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-groovy pull request: Document primitive autowrapping

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-groovy/pull/94


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-groovy pull request: Document primitive autowrapping

Posted by shils <gi...@git.apache.org>.
Github user shils commented on a diff in the pull request:

    https://github.com/apache/incubator-groovy/pull/94#discussion_r37697139
  
    --- Diff: src/spec/doc/core-object-orientation.adoc ---
    @@ -35,6 +35,51 @@ Groovy supports the same primitive types as those defined by the {jls}[Java Lang
     * `boolean` type (exactly `true` or `false`)
     * `char` type (16 bit, usable as a numeric type, representing an UTF-16 code)
     
    +While Groovy declares and stores primitive fields and variables as primitives, because it uses Objects for
    +everything, it autowraps references to primitives. Just like Java, the wrappers it uses are
    +
    +[cols="1,1" options="header"]
    +.primitive wrappers
    +|====
    +| Primitive type
    +| Wrapper class
    +
    +| boolean
    +| Boolean
    +
    +| char
    +| Character
    +
    +| short
    +| Short
    +
    +| int
    +| Integer
    +
    +| long
    +| Long
    +
    +| float
    +| Float
    +
    +| double
    +| Double
    +|====
    +
    +Here's an example using `int`
    +
    +[source,groovy]
    +----
    +include::{projectdir}/src/spec/test/PrimitiveTest.groovy[tags=primitive_references,indent=0]
    +----
    +
    +Now you may be concerned that this means every time you use a mathematical operator on a reference to a primitive
    +that you'll incur the cost of unboxing and reboxing the primitive. But this is not the case, as Groovy will compile
    +your operators into their link:core-operators.html#_operator-overloading[method equivalents] and uses those instead.
    +Additionally, Groovy will automatically unbox to a primitive when calling Java that takes a primitive parameter and
    --- End diff --
    
    'when calling a Java method that takes a primitive parameter..' ? 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---