|
Perhaps slightly misnamed, this package assists in the creation of Object.equals, Object.toString, Object.hashCode, and Comparable.compareTo methods. Generally speaking, each class (CompareToBuilder, EqualsBuilder, HashCodeBuilder, ReflectionToStringBuilder, and ToStringBuilder) allows you to construct an implementation via either select properties or via a reflection-based comparison. They can be used to quickly construct implementations. The StandardToStringStyle and ToStringStyle classes can be used to create formatting rules, which can then be used to control the output of the new toString implementation. For example, the code: Object foo = new Object() { public String[] arrayExample = { "One", "Two", "Three"}; public String foo = "sample"; public String toString() { return new ReflectionToStringBuilder(this).toString(); } }; System.out.println(foo.toString()); . . . produces the output: com.cascadetg.ch10.StringExample$1@1a8c4e7[arrayExample={One,Two,Three}, foo=sample] |
|