class A{
static g2( Integer i ){ i }
def g3( Integer i ){ i }
static g4( int i ){ i }
static g5( Integer i, Integer j ){ [ i, j ] }
}
assert A.g2( new Integer(7) ) == 7
assert A.g2() == null
assert new A().g3( new Integer(8) ) == 8
assert new A().g3() == null
assert A.g4( 7 ) == 7
try{ A.g4(); assert false }catch(Throwable e){ assert e instanceof IllegalArgumentException }
assert A.g5( new Integer(7), new Integer(8) ) == [ 7, 8 ]
try{ A.g5( new Integer(7) ); assert false }catch(Throwable e){ assert e instanceof MissingMethodException }
try{ A.g5(); assert false }catch(Throwable e){ assert e instanceof MissingMethodException }
Can anyone let us know if this is a design decision or not?
We're encountering problems when our developers incorrectly call a function without parameters. They get unexpected behaviour due to forgetting to pass in a parameter and this can take some time to track down when the function allows null as a parameter.