Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 在Flex中使用内省调用静态方法_Apache Flex_Static_Introspection_Method Invocation - Fatal编程技术网

Apache flex 在Flex中使用内省调用静态方法

Apache flex 在Flex中使用内省调用静态方法,apache-flex,static,introspection,method-invocation,Apache Flex,Static,Introspection,Method Invocation,全部, 虽然这与另一个类似,但该帖子(如果可以的话)并未指明如何在不实例化对象的情况下执行该操作。此外,我尝试了以下主题的多种变体,但都没有成功: class[method](arg) class[method].call(arg) method.apply(class, arg) 我是Flex新手,但在C#和Java中都使用了反射。顺便说一句,我试图在Flex中使用的代码在这两种语言中都得到了反映,并且工作正常 感谢您的帮助, 谢谢 托德 不起作用的Flex代码: private f

全部,

虽然这与另一个类似,但该帖子(如果可以的话)并未指明如何在不实例化对象的情况下执行该操作。此外,我尝试了以下主题的多种变体,但都没有成功:

class[method](arg)
class[method].call(arg)
method.apply(class, arg)
我是Flex新手,但在C#和Java中都使用了反射。顺便说一句,我试图在Flex中使用的代码在这两种语言中都得到了反映,并且工作正常

感谢您的帮助, 谢谢 托德

不起作用的Flex代码:

    private function ipMethodTester( ipMethodName:String,
             shouldPass:Array, shouldFail:Array):void
    {
        var message:String;
        var entry:String;
        for each(entry in shouldPass)
        {
            message = ipMethodName + ": " + entry + " should pass";
            try
            {
                Assert.assertTrue(message,
                    FieldValidator[ipMethodName](entry));
            }
            catch(e:Error)
            {
               Assert.fail(e.message + " " + message);
            }
        }
        for each(entry in shouldFail)
        {
            message = ipMethodName + ": " + entry + " should fail";
            try
            {
                Assert.assertFalse(message,
                    FieldValidator[ipMethodName](entry));
            }
            catch(e:Error)
            {
               Assert.fail(e.message + " " + message);
            }
        }
    }
Java代码:

private void ipMethodTester(final String ipMethodName,
         final String[] shouldPass, final String[] shouldFail)
{
   Method method;
   try
   {
      method = InetUtil.class.getDeclaredMethod(ipMethodName, String.class);
      method.setAccessible(true);

      for(String entry : shouldPass)
      {
         Object[] invokeArgs = { entry };
         boolean passed = (Boolean)method.invoke(null, invokeArgs);

         assertTrue(ipMethodName + ": " + entry + " should pass", passed);
      }

      for(String entry : shouldFail)
      {
         Object[] invokeArgs = { entry };
         boolean passed = (Boolean)method.invoke(null, invokeArgs);

         assertFalse(ipMethodName + ": " + entry + " should fail", passed);
      }
  }
  catch (final Exception e)
  {
     fail(e.getClass().toString());
  }
}
C#代码:

这对我很有用:

MyClass['myMethod']('arg1','arg2');
这也适用于:

MyClass['myMethod'].call(MyClass, 'arg1', 'arg2');

注意:“call”方法的第一个参数(本例中为MyClass)只指定在函数中使用“this”关键字时引用哪个对象。

另一篇文章是什么?哪些代码在C#/Java中运行良好?您可以使用ClassName.MethodName在Flex中调用静态方法。不过,我从未尝试使用动态方法名称来实现这一点;我不确定这将如何工作。提供了请求的信息在问题的更新中。Flex代码循环中的try-catch用于调试。Dane,ticks中的单词是否被视为字符串?我得到“Error 1034 Type-impression failed”我已经检查过了,并且我的arg类型与静态方法的arg类型匹配。我不知道强制还可能来自何处。Dane,在原始问题中添加了不起作用的flex代码。嗯,我觉得这很好。我认为问题一定发生在您的代码中的其他地方。Dane,我需要对n参数。传递的所有值都必须是字符串吗?或者您是否指示myMethod接受字符串参数?
MyClass['myMethod'].call(MyClass, 'arg1', 'arg2');