search

Home  >  Q&A  >  body text

java - 能不能加入一种IOC的语法,比如new一个interface

如题,开一下脑洞,各种开发语言能不能把接口变的可以new,实现IOC的效果,而具体实例化的类型是通过类似我们现在使用的IOC框架的注入方式来确定的。

黄舟黄舟2820 days ago753

reply all(3)I'll reply

  • 阿神

    阿神2017-04-17 17:54:20

    Since it is injected, why do you need new interface?

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 17:54:20

    new interface has no meaning

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:54:20

    Do you want to use IoC as a language feature, or native support?

    For new Interface, custom language based on JVM implementation is actually possible.

    In addition to the source code, add a configuration file control.
    Configuration file as preprocessing control.
    When compiling, first preprocess the pure source code file (the object has been injected).
    Compile the preprocessed source code file afterwards.
    The above is how static injection (compile-time injection) is handled.

    In addition, obviously, from Spring, we can know that it is possible to use reflection to achieve the effect of dynamic injection, as long as we make corresponding changes in semantic analysis and write a usable IoC standard library.

    It’s easy to say it, but it’s not easy to implement.

    reply
    0
  • Cancelreply