Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is groovy weakly typed or strongly typed?

Tags:

groovy

typing

I don't understand how groovy typing works. On wikipedia it is written that it has a strong typing, but I can perfectly do that on the interpreter :

1 + '1'
==> 11

So maybe I am confused and I didn't understand what weak typing is, but I'd like to know what this feature is then.

like image 555
PerrierCitror Avatar asked Oct 01 '22 18:10

PerrierCitror


1 Answers

It's not an issue of weakly or strictly typed languages. As delnan show, there is a weary slick theme, and terminology here can be different.

What do you see in interpreter, is a work of overloaded plus operator, which allows you easy concatenate values into strings, very useful feature for printing some output or logging.

To be specific, Groovy is weakly(optionally, as tim suggested) typed, you can define types, or you can omit them, using def keyword. It also allows you to do a lot of implicit conversions, because of it dynamic nature. More info about types. There are several annotations, allowing you to change that behaviour, like @CompileStatic or @TypeChecked.

In every particular situation, you can get better solution, using right typing strategy. It's very Groovy ;)

like image 109
Seagull Avatar answered Oct 05 '22 11:10

Seagull