有没有办法判断函数是返回值还是返回void?
我尝试过使用describeType,这就是它返回的内容:
<type name="builtin.as$0::MethodClosure" base="Function" isDynamic="false" isFinal="true" isStatic="false">
<extendsClass type="Function"/>
<extendsClass type="Object"/>
<accessor name="length" access="readonly" type="int" declaredBy="Function"/>
<accessor name="prototype" access="readwrite" type="*" declaredBy="builtin.as$0::MethodClosure"/>
</type>
我传入了一个返回值的函数和一个返回void的函数。两者都返回上面相同的XML值。
以下是功能和代码:
public function getElementCount(o:Object, count:String):String {
return count;
}
public function getElementCount2(object:Object, count:String):void {
}
var o:Object = mx.utils.DescribeTypeCache.describeType(getElementCount).typeDescription;
var o2:Object = mx.utils.DescribeTypeCache.describeType(getElementCount2).typeDescription;
答案 0 :(得分:2)
只需将getQualifiedClassName(input)
与您的功能一起用作输入。
示例代码:
package
{
import flash.display.MovieClip;
import flash.utils.getQualifiedClassName;
public class Get_Return_Type extends MovieClip
{
public function Get_Return_Type()
{
//# Check 1
trace("check : function getElementCount");
trace( "returns type : " + getQualifiedClassName( getElementCount(null, "test") ) );
//# Check 2
trace("check : function getElementCount2");
trace( "returns type : " + getQualifiedClassName( getElementCount2(null, "test") ) );
}
public function getElementCount(o:Object, count:String):String
{ return count; }
public function getElementCount2(object:Object, count:String):void
{ }
}
}
跟踪结果:
检查:函数getElementCount
返回类型:
String
检查:函数getElementCount2
返回类型:
void