Skip to content

Navigation Menu

Sign up

JAXB2 HashCode Plugin

Laurent Schoelens edited this page Aug 28, 2023 · 2 revisions

HashCode plugin

HashCode plugin generates hashCode(...) methods:

public class PurchaseOrderType
 implements HashCode //, ...
 // ... 
 public int hashCode() {
 final HashCodeStrategy strategy = JAXBHashCodeStrategy.INSTANCE;
 return this.hashCode(null, strategy);
 }
 public int hashCode(ObjectLocator locator, HashCodeStrategy strategy) {
 int currentHashCode = 1;
 {
 USAddress theShipTo;
 theShipTo = this.getShipTo();
 currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "shipTo", theShipTo), currentHashCode, theShipTo);
 }
 {
 USAddress theBillTo;
 theBillTo = this.getBillTo();
 currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "billTo", theBillTo), currentHashCode, theBillTo);
 }
 // ...
 return currentHashCode;
 }
 // ...
}

Generated methods allow you to specify a custom hash code strategy (hash code strategy).

Activation

Use the -XhashCode argument to activate the plugin.

Configuration

By default, generated code uses org.jvnet.jaxb2_commons.lang.JAXBHashCodeStrategy as hash code strategy. You can specify class name of your custom strategy using the -XhashCode-hashCodeStrategyClass argument:

-XhashCode-hashCodeStrategyClass=com.acme.foo.CustomHashCodeStrategy

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /