o*****l 发帖数: 539 | 1 Is there a way that we could invoke a function dynamically?
For example, at some point of the program, I need to call a function, but
the function name, input parameters need to be dynamic, which will be define
in a config file, loaded when the program start. The function always
return a integer.
the config file like this:
| g*****g 发帖数: 34805 | 2 You can either build on top of reflection APi to do this,
or spring api has something similar.
define
【在 o*****l 的大作中提到】 : Is there a way that we could invoke a function dynamically? : For example, at some point of the program, I need to call a function, but : the function name, input parameters need to be dynamic, which will be define : in a config file, loaded when the program start. The function always : return a integer. : the config file like this: : : : :
| k***r 发帖数: 4260 | 3 Or you can use a fixed function name but dynamic class name.
I think it's easier this way.
but
define
【在 o*****l 的大作中提到】 : Is there a way that we could invoke a function dynamically? : For example, at some point of the program, I need to call a function, but : the function name, input parameters need to be dynamic, which will be define : in a config file, loaded when the program start. The function always : return a integer. : the config file like this: : : : :
| g**********y 发帖数: 14569 | 4 少写reflective的code, 多活20年。写的时候看上去很neat, 但是debug reflective的
code真的是nightmare, 哪怕是你自己写的。
感觉reflective就象花credit card, 用的时候很爽,还钱的时候很痛! | T*********g 发帖数: 496 | 5 if your methods are encapculated in specific class, java reflection will
meet your requirement.
define
【在 o*****l 的大作中提到】 : Is there a way that we could invoke a function dynamically? : For example, at some point of the program, I need to call a function, but : the function name, input parameters need to be dynamic, which will be define : in a config file, loaded when the program start. The function always : return a integer. : the config file like this: : : : :
| b******y 发帖数: 1684 | 6 哈哈
写的时候是"i can handle every case"
debug的时候是"I can't even handle myself"
【在 g**********y 的大作中提到】 : 少写reflective的code, 多活20年。写的时候看上去很neat, 但是debug reflective的 : code真的是nightmare, 哪怕是你自己写的。 : 感觉reflective就象花credit card, 用的时候很爽,还钱的时候很痛!
| A**o 发帖数: 1550 | 7 我是先debug过别人的reflection代码,于是从此敬而远之。
【在 b******y 的大作中提到】 : 哈哈 : 写的时候是"i can handle every case" : debug的时候是"I can't even handle myself"
| r*****l 发帖数: 2859 | 8 这个比喻有点意思。
不过reflection没有那么可怕了。话说回来,如果reflection能
被其它东西实现,Java里面也不会有reflection了。
【在 g**********y 的大作中提到】 : 少写reflective的code, 多活20年。写的时候看上去很neat, 但是debug reflective的 : code真的是nightmare, 哪怕是你自己写的。 : 感觉reflective就象花credit card, 用的时候很爽,还钱的时候很痛!
| c******n 发帖数: 4965 | 9 我是新手啊
我觉得reflection 其实就是abstract,delegation 的concept 到extreme, |
|