小编cac*_*tus的帖子

如何在Erlang中动态调用模块?

假设我有两个模块a.erlb.erl.两个模块都包含相同的功能(在Java中我会说"两个类都实现相同的接口").在模块"c.erl"中我想要一个将返回模块"a"或"b"的函数(取决于参数)

这是我想要在模块c.erl中拥有的内容

-module(c)

get_handler(Id) ->

 % if Id == "a" return a

 % if Id == "b" return b

test() ->

 get_handler("a"):some_function1("here were go for a"),

 get_handler("a"):some_function2("aaaa"),

 get_handler("b"):some_function1("here we go for b")
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?我对Erlang比较新,不知道怎么做.在Java中,这将是非常明显的,因为您只返回类的新实例.

erlang

5
推荐指数
2
解决办法
387
查看次数

标签 统计

erlang ×1