6 Replies Latest reply on Aug 17, 2008 8:11 PM by Kamil Demecki

    lazily initialize collections in their getters

    mars1412 Apprentice

      I am thinking of using lazy initialization of collections in thier getters:
      example:

      private java.util.Set<MyEntity> myEntities;
      
       public java.util.Set<MyEntity> getMyEntities() {
       if (myEntities == null) {
       myEntities = new HashSet<MyEntity>();
       }
       return myEntities;
      
       }



      this would be nice because I would not need the explicit null checks in my buissneslogic.

      however I have a bad feeling about this - I'm if this will work in all cases with lazy loading, hibernate proxies and stuff I might not even know about.

      What do you think?