Description of interesting language facet #2
In Groovy, objects are used for almost everything. Due to the fact that Groovy uses objects, Groovy automatically will wrap the types of variables in the code. Something that is worth mentioning is boxing and unboxing. When the coder is converting a primitive data type to an object it is called unboxing. Likewise, when the coder is converting an object to a primitive data type. For clarification purposes, there are eight primitive types which are boolean , byte , char , short , int , long , float and double.
In Java, widening is done before boxing is done. Widening is defined as taking a small primitive type value and is automatically accommodated in a bigger primitive data type.
The first method is the method that Java prioritizes because it does widening rather than boxing. However, for Groovy, the second method would be the method that would be called because no matter what circumstances, Groovy automatically makes the primitive type use the primitive data types wrapper. In this case for "int", it would call the method that is its wrapper class which for this would be Integer.
Sources
"Differences with Java." The Apache Groovy Programming Language - Differences with Java, groovy-lang.org/differences.html#_arm_blocks
Automatic Resource Management in Java, www.tutorialspoint.com/Automatic-resource- management-in-Java

Comments
Post a Comment