dtjbcda841554 2019-07-22 21:31 采纳率: 0%
浏览 190

我们可以在go中动态创建函数吗?

I'm trying to create a service where a user needs to operate over a data and can manipulate it in numerous ways, so I'm not aware of the manipulations at the time of compiling of my program. One way to achieve this is to give the user a function with data as param. Which landed me in the following direction.

  1. Dynamically create a function
  2. Dynamically linking a function after compiling it separately.

I'm open to suggestions. If you have other ways to achieve the end goal.

  • 写回答

1条回答 默认 最新

  • dthtvk3666 2019-07-22 22:43
    关注

    If you don't like this as an answer I can move to the comment section, but it's rather long that's why I put here in the answer section.

    1. Dynamically Dispatched Method: The only way to have dynamically dispatched methods is through an interface. Methods on a struct or any other concrete type are always resolved statically.

    2. Closure: Go supports anonymous functions, which can form closures. Anonymous functions are useful when you want to define a function inline without having to name it.

    3. Dyncamically call method on Interface:

    Please let me know if that helps you to understand the concept in golang.

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?