my dog learned polymorphism*
The moose likes Groovy and the fly likes Groovy and generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Groovy and generics" Watch "Groovy and generics" New topic
Author

Groovy and generics

Fedor Belov
Greenhorn

Joined: Feb 02, 2012
Posts: 2
Hello
Why does this code compile and execute correctly?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3054
    
  33

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
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3054
    
  33

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Groovy and generics
 
Similar Threads
JSecure Exam Simulation has now changed !!!
i did terrible.
Dont miss this tutorial !!
Program Output
Overriding and redefining