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 - Groovy Tutorial
From the course: Learning Groovy
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Groovy and Java3m 21s
-
(Locked)
Variables and data types2m 54s
-
Classes and methods2m 46s
-
(Locked)
Conditional structures and loops2m 51s
-
(Locked)
Exception handling2m 35s
-
(Locked)
Using the GDK documentation2m 25s
-
(Locked)
Challenge: Creating and using a class1m 37s
-
(Locked)
Solution: Creating and using a class7m 10s
-
-
-