Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

EHC.HASH

The EHC Class should implement both equals(Object) and hashCode() methods. EHC warnings appear if an equals() method was specified without a hashCode() method, or vice versa. This may cause a problem with some collections that expect equal objects to have equal hashcodes.

Example 1

8  public class EHC_HASH_Sample_1 {
9      private int seed;
10     public EHC_HASH_Sample_1(int seed) {
11         this.seed = seed;
12     }
13     public boolean equals(Object o) {
14         return (o instanceof EHC_HASH_Sample_1)
15                && ((EHC_HASH_Sample_1) o).seed == seed;
16     }
17     // no hashCode method defined
18 }

EHC.HASH is reported for class declaration on line 8: Class defines equals() but does not define hashCode().

Related checkers