Find out what variable is throwing a NullPointerException programmatically

后端 未结 8 1632
醉酒成梦
醉酒成梦 2020-12-05 10:30

I know I can find out if a variable is null in Java using these techniques:

  • if (var==null) -> too much work
  • try { ... } catch (Null
8条回答
  •  时光说笑
    2020-12-05 10:56

    I think you should notice Demeters Law.

    There aren't many people following it strictly, because it results in a lot of delegate methods.
    But getting too far from it will result in dependencies on inner structures that should be transparent.

提交回复
热议问题