|
Groovy example source code file (ClassExpressionTest.groovy)
The Groovy ClassExpressionTest.groovy source code
package groovy
/**
* Tests the use of classes as variable expressions
*
* @author <a href="mailto:james@coredevelopers.net">James Strachan
* @version $Revision: 4996 $
*/
class ClassExpressionTest extends GroovyTestCase {
void testUseOfClass() {
def x = String
System.out.println("x: " + x)
assert x != null
assert x.getName().endsWith('String')
assert x.name.endsWith('String')
x = Integer
assert x != null
assert x.name.endsWith('Integer')
x = GroovyTestCase
assert x != null
assert x.name.endsWith('GroovyTestCase')
x = ClassExpressionTest
assert x != null
System.out.println("x: " + x)
}
void testClassPsuedoProperty() {
def x = "cheese";
assert x.class != null
assert x.class == x.getClass();
System.err.println( "x.class: " + x.class );
}
void testPrimitiveClasses() {
assert void == Void.TYPE
assert int == Integer.TYPE
assert byte == Byte.TYPE
assert char == Character.TYPE
assert double == Double.TYPE
assert float == Float.TYPE
assert long == Long.TYPE
assert short == Short.TYPE
}
void testArrayClassReference() {
def foo = int[]
assert foo.name == "[I"
}
}
Other Groovy examples (source code examples)Here is a short list of links related to this Groovy ClassExpressionTest.groovy source code file: |
Other websites by Alvin Alexander:
Life/living in Alaska (OneMansAlaska.com)
How I Sold My Business (HowISoldMyBusiness.com)
Copyright 1998-2011 Alvin Alexander, devdaily.com
All Rights Reserved.