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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---