This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Every closure in groovy is executable, and technically, implements the "Callable" interface | |
def a = { println "hello!"} | |
a() | |
// --> hello | |
a.call() | |
// --> hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def messageTo = { num -> | |
println(Thread.currentThread().name + " --> A message for you number $num") | |
} | |
def pool = Executors.newFixedThreadPool(10) | |
(1..1000).each { num -> | |
pool.submit({ messageTo(num) }) | |
} | |
pool.awaitTermination(60, TimeUnit.SECONDS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fish (var fishName: String){ | |
private var myName = fishName | |
def name = myName | |
def name_= (newName: String) = myName = newName | |
def sayHello(otherFish : Fish) = println ("hello, " + otherFish.myName) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fish { | |
private var name = "Default" | |
def getName = name | |
def setName(newName: String) = name = newName | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fish { | |
private var myName = "Default" | |
def name = myName | |
def name_= (newName: String) = myName = newName | |
} |
NewerOlder