Topic: 如何获取字符串变量所对应的值 |
Print this page |
1.如何获取字符串变量所对应的值 | Copy to clipboard |
Posted by: wtuyzh Posted on: 2005-04-20 00:03 例如:double x=2.0; str="x"; 我想编个函数double getValue(str)实现: getValue(str)=2.0 困惑了好几天,帮忙想想吧,谢谢啦! |
2.Re:如何获取字符串变量所对应的值 [Re: wtuyzh] | Copy to clipboard |
Posted by: wtuyzh Posted on: 2005-04-20 00:14 还有:int x=3; inty=5; String str="x+y"; 要求结果: getValue(str)=8 |
3.Re:如何获取字符串变量所对应的值 [Re: wtuyzh] | Copy to clipboard |
Posted by: why Posted on: 2005-04-20 00:22 I don't think it is possible with Java for non-class member, do you just want a scripting language on top of Java? |
4.Re:如何获取字符串变量所对应的值 [Re: wtuyzh] | Copy to clipboard |
Posted by: wtuyzh Posted on: 2005-04-20 00:42 Please consider using the editing feature instead of making a new post 其实是我写了个程序,可以画任意函数的图像,我有个Function()方法获取函数名 public double Function(double x){ return 函数名; } 现在是不知道怎么得到函数名,因为从JTextField得到的是字符串表达式 public double Function(double x){ return math.cos(x); } 程序运行成功 |
5.Re:如何获取字符串变量所对应的值 [Re: wtuyzh] | Copy to clipboard |
Posted by: 凤舞凰扬 Posted on: 2005-04-22 16:23 其实楼上的问题就是文法规则解析,这里面包含两个问题,第一,就是文法规则解析,第二就是解析的变量的值访问。 第一个我相信楼主可以解决,谈谈第二个,楼主如果熟悉反射(reflect),也就可以找到某个类对应的可访问的属性和方法,从而得到它的值。这种技术在规则引擎中是非常基础的。 |
6.Re:如何获取字符串变量所对应的值 [Re: wtuyzh] | Copy to clipboard |
Posted by: wtuyzh Posted on: 2005-04-23 12:17 谢谢提醒,我不熟reflect,看书去! 再次感谢! |
7.Re:如何获取字符串变量所对应的值 [Re: wtuyzh] | Copy to clipboard |
Posted by: cooljop Posted on: 2005-04-25 15:10 hashtable不行么?^_^ |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |