Skip to content

Instantly share code, notes, and snippets.

View osscontributor's full-sized avatar

OSS Contributor osscontributor

View GitHub Profile
@groovy.transform.CompileStatic
class TwoException extends Exception {
public TwoException(Throwable t) {
super(t)
}
}
public TwoException(java.lang.Throwable);
Code:
0: iconst_1
core 2.3.x $ ./gradlew -Dtest.single=BinaryPluginSpec :grails-core:test --stacktrace
:buildSrc:compileJava UP-TO-DATE
:buildSrc:compileGroovy UP-TO-DATE
:buildSrc:processResources UP-TO-DATE
:buildSrc:classes UP-TO-DATE
:buildSrc:jar UP-TO-DATE
:buildSrc:assemble UP-TO-DATE
:buildSrc:compileTestJava UP-TO-DATE
:buildSrc:compileTestGroovy UP-TO-DATE
:buildSrc:processTestResources UP-TO-DATE
public interface MyInterface<T extends MyInterface> {
T someMethod();
}
public class FirstWidget implements MyInterface<FirstWidget> {
public FirstWidget someMethod() {
return this;
}
}
@osscontributor
osscontributor / gist:9a873cce2acfd1561e3d
Created June 12, 2014 18:13
Stuff generated for an empty class...
groovyquestion $ cat Demo.groovy
class Demo {
// this is an empty class
}
groovyquestion $
groovyquestion $ groovyc Demo.groovy
groovyquestion $
groovyquestion $ javap -private Demo
Compiled from "Demo.groovy"
public class Demo implements groovy.lang.GroovyObject {
mapstuff $ cat demo.groovy
// This is just an example to demonstrate a possibilty,
// not a recommendation of best practice.
Map.metaClass.someMethodName = { key, defaultValue ->
delegate.containsKey(key) ? delegate[key] : defaultValue
}
def map = [name: 'Jeff', town: 'St. Louis']
/*
Apparently http://stackoverflow.com/users/2970947/elliott-frisch doesn't believe that
Java enums can have state.
http://stackoverflow.com/questions/24447233/store-enum-class-reference?noredirect=1#comment37829803_24447233
*/
public enum MyEnum {
ONE(1), TWO(2);
public int value;
grails11577 $ java -version
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b106)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b48, mixed mode)
grails11577 $
grails11577 $ cat application.properties
#Grails Metadata file
#Fri Jul 11 14:22:05 CDT 2014
app.grails.version=2.4.2
app.name=grails11577
@Grab(group='org.gperfutils', module='gbench', version='0.4.2-groovy-2.1')
def smallList = [[first: 'John', last: 'test']]
def largListWithMatchAtEnd = []
10000.times { largListWithMatchAtEnd << [first: 'Johnx', last: 'test'] }
largListWithMatchAtEnd << [first: 'John', last: 'test']
def largListWithMatchInCenter = []
5000.times { largListWithMatchInCenter << [first: 'Johnx', last: 'test'] }
@osscontributor
osscontributor / gist:d4b48dd3022047c2a7d0
Created August 5, 2014 19:17
Demonstrating bi-directional dependencies between Groovy and Java
joint_compile $ ls
FirstGroovy.groovy FirstJava.java SecondGroovy.groovy SecondJava.java
joint_compile $ cat FirstGroovy.groovy
class FirstGroovy {
FirstJava firstJava
}
joint_compile $ cat FirstJava.java
public class FirstJava {
SecondGroovy secondGroovy;
trait $ cat SomeTrait.groovy
trait SomeTrait {
int getMagicNumber() {
42
}
}
trait $ cat SomeClass.groovy
class SomeClass implements SomeTrait {
static magicNumber = 'Forty Two'
}