| Author |
Groovy and generics
|
Fedor Belov
Greenhorn
Joined: Feb 02, 2012
Posts: 2
|
|
Hello
Why does this code compile and execute correctly?
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2694
|
|
|
Groovy is a dynamically typed language and hence your variables need not be assigned the type information as these are determined dynamically at run time. That is the reason why the code executes without issues
|
Mohamed Sanaulla | My Blog
|
 |
Fedor Belov
Greenhorn
Joined: Feb 02, 2012
Posts: 2
|
|
Does it mean that generics are useless?
This code executes the same
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2694
|
|
|
Groovy wasnt designed to behave like Java, it was designed to create a language which in dynamically typed, easy to program. Even in Java the Generics information is not part of the code at runtime, you might want to read about Type Erasure. So when it comes to Groovy it doesnt even consider the type information you specify during the generic declaration. Its there to help you use Java API. You can read more about it here.
|
 |
 |
|
|
subject: Groovy and generics
|
|
|