douzhuan4406 2013-03-10 09:56
浏览 16

是否可以接收实现特定接口的所有结构?

I checked the reflect package documentation, but didn't find anything. What i'm trying to do is find all structs, that implement interface x. Then iterate over all the structs to execute an action y.

  • 写回答

2条回答 默认 最新

  • donglin1192 2013-03-10 10:08
    关注

    This cannot be done at runtime, but only statically by inspecting the program packages (and all of the imports recursively). Or by statically inspecting the generated .{o,a} files.

    However, one may manually build a list of types (not limited to only structs, why?) satisfying an interface:

    if _, ok := concreteInstance.(concreteInterface); ok {
            // concreteInstance satisfies concreteInterface
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题