Home  >  Q&A  >  body text

java - bean 用引用类型好还是用基本类型?

两者有什么判别的标准在什么情况下使用基本类型,还是使用引用类型?

PHP中文网PHP中文网2741 days ago398

reply all(2)I'll reply

  • 怪我咯

    怪我咯2017-04-17 17:49:08

    Generally speaking, basic types are preferred. In the following two situations, reference types are preferred

    1. POJO object corresponding to the database table

    2. HTTP Request Form Object

    Reference types have more null support than basic types, and of course have more possibilities for NullPointerException

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:49:08

    It is recommended not to use basic types, but to use package types. For example, when using int, use Integer, and when using long, use Long, because if your object is to operate on the database, you need to use ORM, and if you use basic types The value when the object is initialized is 0, and the second packaging type is null. ORM will not judge 0 during operation, but it will judge null back, so it is recommended to use the packaging type.

    reply
    0
  • Cancelreply