beanshall方法

本文介绍了beanshell中动态类型的特性及应用,展示了如何利用动态类型进行灵活的编程,包括动态参数和返回值的使用,以及当方法未显式设置返回值时的行为。
beanshall支持动态类型,方法可以有动态的参数和返回值,在调用的时候决定这些类型,并试图做正确的处理。这和javascript一样。
e.g.

add(a,b){
return a+b;
}

foo=add(1,2);//foo=3
foo=add("h","i");//foo="hi"



[quote]
If the method does not perform an
explicit "return" statement and the return type is not explicitly set to void, the value of the last statement or
expression in the method body becomes the return value (and must adhere to any declared return typing).
[/quote]
这句话的意思是:如果方法体的最后一句不是return子句并且返回类型不是void,最后一句表达式的值会成为返回值。
e.g.

add(a,b){
k=a+b;
}
foo=add(1,2);//foo=3

err(){
print(99);
}
foo=err();// Error: EvalError: Void assignment. : at Line: 1 : in file: <unknown file> : foo = err ( )
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值