The moose likes Groovy and the fly likes Question for Mr. Davis Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Other Languages » Groovy
Reply Bookmark "Question for Mr. Davis" Watch "Question for Mr. Davis" New topic
Author

Question for Mr. Davis

Bill Barbour
Ranch Hand

Joined: Dec 19, 2002
Posts: 35
Typing is optional in groovy correct? So does it attempt to derive type when compiling to byte code or is everything just Object?
S Davis
Author
Ranch Hand

Joined: Feb 07, 2006
Posts: 40
Typing is optional in Groovy. If you care about the datatype, then specify the datatype. If you don't, don't. (I'm not being flippant -- honest!)



I tend to use types less when I am completely in Groovy, and use them more when I am talking to strongly typed things like Java and databases. But never forget that the types are still there -- we are on the JVM, after all.



In Java, you tend to do more polymorphic/interface-driven development. class Ipod implements Player -- that sort of thing. In Groovy, you can absolutely continue down that route -- Groovy class can implement Java interfaces and vice versa -- but pure Groovy development tends to be more about duck-typing. This means that I honestly don't care about the type of the class as long as it responds to my method call. This makes mocking and testing an order of magnitude easier, but that's a whole 'nother topic, isn't it? (grin)
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18641
[Bill]: Typing is optional in Groovy.

Which is a big win for programmers suffering from carpal tunnel, I'm sure. Scott (or "S" if you prefer ), can you tell us about the new telepathic interface-driven development techniques? You basically just think at the screen and the code appears, right?

OK, sorry, I just had to get that out of my system. Welcome to JavaRanch, Scott!


"I'm not back." - Bill Harding, Twister
 
 
subject: Question for Mr. Davis
 
developer file tools