@Embeddable
@Embedded
@EmbeddedId
http://www.thejavageek.com/2014/05/01/jpa-embeddedid-example/
Tuesday, June 16, 2015
Monday, June 8, 2015
Effective Java - Chapter 07
Item 38: Check parameters for validity
Item 39: Defensive copy
- Detect errors as soon as possible
- For public methods, use the Javadoc @throws tag to document the exception that will be thrown if a restriction on parameter values is violated
- Non-public methods should generally check their parameters using assertions.
In summary, if a class has mutable components that it gets from or returns to its clients, the class must defensively copy these components. If the cost of the copy would be prohibitive andthe class trusts its clients not to modify the components inappropriately, then the defensive copy may be replaced by documentation outlining the client’s responsibility not to modify the affected components.
- You must program defensively, with the assumption that clients of your class will do their best to destroy its invariant.
- experienced programmers often use the primitive long returned by Date.getTime() as an internal time representation instead of using a Date reference. They do this primarily because Date is mutable.
- Defensive copying can have a performance penalty associated with it and isn’t always justified.
Subscribe to:
Comments (Atom)