Wednesday, September 9, 2009

Groovy Optional Datatype Declaration (Duck Typing) Step 10

Java is a statically typed language. That means that each variable has to have a datatype when you declare it. Groovy, on the other hand, allows you to define variables without a datatype.


For example:

def name='Greg' means that the variable name is a String. The keyword def means that it doesn't much care what type the variable is.

You can write,

def y="Hello"
String z="Hello"
println w.class
println w.class==x.class


Go To Step 11

0 comments: