Examples

C1.java
01/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */ 02 03package com.db4odoc.constructors; 04 05class C1 { 06 private String s; 07 08 private C1(String s) { 09 this.s=s; 10 } 11 12 public String toString() { 13 return s; 14 } 15 }

The above class is fine for use with and without callConstructors set.

C2.java
01/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */ 02 03package com.db4odoc.constructors; 04 05class C2 { 06 private transient String x; 07 private String s; 08 09 private C2(String s) { 10 this.s=s; 11 this.x="x"; 12 } 13 14 public String toString() { 15 return s+x.length(); 16 } 17 }

The above C2 class needs to have callConstructors set to true. Otherwise, since transient members are not stored and the constructor code is not executed, toString() will potentially run into a NullPointerException on x.length().

C3.java
01/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */ 02 03package com.db4odoc.constructors; 04 05class C3 { 06 private String s; 07 private int i; 08 09 private C3(String s) { 10 this.s=s; 11 this.i=s.length(); 12 } 13 14 public String toString() { 15 return s+i; 16 } 17 }

The above C3 class needs to have callConstructors set to false (the default), since the (only) constructor will throw a NullPointerException when called with a null value.

C4.java
01/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */ 02 03package com.db4odoc.constructors; 04 05class C4 { 06 private String s; 07 private transient int i; 08 09 private C4(String s) { 10 this.s=s; 11 this.i=s.length(); 12 } 13 14 public String toString() { 15 return s+i; 16 } 17 }

This class cannot be cleanly reinstantiated by db4o: both approaches will fail, so one has to resort to configuring a translator.