Skip to content

Instantly share code, notes, and snippets.

@pditommaso
Forked from timyates/forceOverrideTraits.groovy
Created April 9, 2014 13:19
Show Gist options
  • Save pditommaso/10269533 to your computer and use it in GitHub Desktop.
Save pditommaso/10269533 to your computer and use it in GitHub Desktop.
@Grab('org.slf4j:slf4j-api:1.6.1')
@Grab('ch.qos.logback:logback-classic:0.9.28')
import org.slf4j.*
import groovy.transform.*
trait Loggable {
@Memoized getLog() {
LoggerFactory.getLogger( this.getClass() )
}
}
class Test implements Loggable {
def foo() {
log.debug( 'Woo. In foo' )
}
}
class Test2 implements Loggable {
def bar() {
log.info( 'Ha. In bar' )
}
}
new Test().foo()
new Test2().bar()
import groovy.transform.*
@CompileStatic
trait IgnoredRemovable {
void remove() {}
}
@CompileStatic
trait Endless {
boolean hasNext() { true }
}
@CompileStatic
trait EndlessIterator<T> implements IgnoredRemovable, Endless, Iterator<T> {
T value
T next() { value }
}
@CompileStatic
class LoadsOfOnes implements EndlessIterator<Integer> {
LoadsOfOnes() {
value = 1
}
}
assert new LoadsOfOnes().take( 5 ).collect() == [ 1, 1, 1, 1, 1 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment