beanshell 内部类
我想使用我的java代码作为beanshell脚本,但beanshell抛出异常说在命名空间中找不到类。 beanshell中没有内部类还是有其他用途?
我的脚本如下所示:
.......
.......
java code
.......
.......
MyClass m = new MyClass(); //Error here: MyClass not fount in namespace
class MyClass {
}
我在脚本中使用内部类,我在脚本中声明了该内部类。
谢谢, 比拉尔
i wanted to use my java code as beanshell script but beanshell throws Exception saying class not found in namespace. Isn't there inner class in beanshell or does it have any other usage?
my script looks like here:
.......
.......
java code
.......
.......
MyClass m = new MyClass(); //Error here: MyClass not fount in namespace
class MyClass {
}
i use the inner class in script, which i declare in the script.
Thanks,
Bilal
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许这里的答案很愚蠢,但是 MyClass 定义是否需要高于其在文件中的用法? bean shell 不是线性处理脚本吗?
快速浏览一下文档并不能说明这一点,但以下脚本的测试对我来说确实效果很好:
Maybe a silly answer here but could it be that the MyClass definition needs to be above its usage in the file? Doesn't bean shell process scripts linearly?
A quick look in the docs doesn't spell this out but tests of the following script certainly works fine for me:
BeanShell 不支持类定义。
您可以使用 BeanShell 内部类语法来实现接口:
或者
在您的情况下,我认为您最好使用脚本对象方法:
Class definition is not supported by BeanShell.
You can use BeanShell inner class syntax to implement an interface:
Or
In your case I think you are better off going with the scripted object approach:
附加信息:匿名内部类作为参数无法使用,因此您需要将实现分配给变量。 (在 JMeter 中)
不起作用:
起作用:
希望它能帮助别人。
Additional information: the anonymous inner class as argument can not use, so you need to assign your implementation to a variable. (In JMeter)
Not works:
Works:
Hope it will help out someone.