I am writing codes that query the database to get the data. There are some classes that consist of List
s, but sometime the list or other attribute can not be initiated and their value is null
, so I need to write list!=null || list.isEmpty
or attribute != null
, before I can use the attribute.
Unfortunately, it easy to forget it, and I really think it is ugly to do it every time when I operate an attribute. I am going to write some code to explain it.
public class SpotVo {
private Double avg;
private String brief;
private ArrayList<HotelVo> hotels;
private int id;
private ArrayList<byte[]> images;
private AddressVo location;
private String name;
private ArrayList<RestaurantVo> restaurants;
}
As you can see, there are some lists and other attributes in this class, there can all be null
or empty, can I do something to avoid it?