search

Home  >  Q&A  >  body text

JAVA接口对象为空时,调用接口方法,程序没报错

黄舟黄舟2781 days ago979

reply all(5)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 13:58:59

    If you are sure to execute test.eat(); when using the framework and no error is reported, it is indeed interesting.
    It is also possible that the framework swallowed the exception and threw it upward

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:58:59

    Try it and NPE will appear
    http://www.tutorialspoint.com/compile_java_online.php?PID=0Bw_CjBb95KQ...

    reply
    0
  • 阿神

    阿神2017-04-17 13:58:59

    I dare say that you must have not read the code. If it returns a null, then this is completely meaningless code. If this is really the case, is it normal if you delete the project...
    The getModel method must return the object implemented by the interface.
    You can search for the class that implements that interface. Take a closer look at the configuration file of the class related to the getModel method.
    Look carefully... nothing so magical will happen...

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:58:59

    Cannot be empty. If no error is reported, the framework must have caught the exception handling for you.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:58:59

    I think you may have followed the wrong code. You can see what you get after executing ITest test = Model.getModel(); by debugging with breakpoints

    reply
    0
  • Cancelreply