Groovy is an “optionally” typed language, When compared to Java, which is a “strongly” typed language,
whereby the compiler knows all of the types for every variable and contracts at compile time. This means that method calls are able to be determined at compile time.
In Groovy, optional typing is done via the ‘def’ keyword.
class Example {
static void main(String[] args) {
// Example of an Integer using def
def a = 100;
println(a);
// Example of an float using def
def b = 100.10;
println(b);
// Example of an Double using def
def c = 100.101;
println(c);
// Example of an String using def
def d = "HelloWorld";
println(d);
}
}
No comments:
Post a Comment