Hibernate query.list() method is returning empty list instead of null value

前端 未结 2 1050
你的背包
你的背包 2021-02-01 01:15

When there are no rows, both query.list() and criteria.list() are returning empty list instead of a null value.

What is t

2条回答
  •  别那么骄傲
    2021-02-01 01:55

    The reason is not to force null checks in client code, in consistency with Effective Java 2nd Edition, Item 43: Return empty arrays or collections, not nulls.

    This makes the client code simpler and less error-prone (and most likely the method implementation as well).

    The null-return idiom is likely a holdover from the C programming language, in which array lengths are returned separately from actual arrays. In C, there is no advantage to allocating an array if zero is returned as the length.

提交回复
热议问题