From the course: Learning Groovy

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Variables and data types

Variables and data types - Groovy Tutorial

From the course: Learning Groovy

Start my 1-month free trial

Variables and data types

- [Instructor] Let's dive deeper into Groovy's functionality. We'll start by having a look at variables and typing. In this example we'll extend the code from the previous exercise. In Groovy you can define a variable similar to the way you do it in Java. You specify a variable name, and assign value. Here we are representing the age of a person and the value 40. Now you can see that the IDE complains about the fact that we didn't assign a type. Obviously we are dealing with a number. So let's use an integer here. Remember that you can use all the data types you already know from Java. Next, we will print out the value. As expected, the console renders the number 40. Let's also ensure that Groovy treats the variable properly by using the right type. Let's print out the type as well. As you can see, the class of the variable is java.lang.Integer. I mentioned earlier that Groovy doesn't enforce static typing by…

Contents