NOTE: I noticed that some of the readers are getting database connection issues. Notice that in my pom.xml, there is no database driver. That works for me because I have MySQL driver in tomcat lib directory and some DataSource connections configured with it. For any database connection related issues, either put the database driver in container lib or include that in pom.xml dependencies.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.4</version>
</dependency>
Store some constant nonzero value, say 17, in an int variable called result.
Compute an int hashcode c for each field f that defines equals:
- If the field is a boolean, compute (f ? 1 : 0)
- If the field is a byte, char, short, int, compute (int) f
- If the field is a long, compute (int) (f ^ (f >>> 32))
- If the field is a float, compute Float.floatToIntBits(f)
- If the field is a double, compute Double.doubleToLongBits(f), then hash the resulting long as in above.
- If the field is an object reference and this class's equals method compares the field by recursively invoking equals, recursively invoke hashCode on the field. If the value of the field is null, return 0.
- If the field is an array, treat it as if each element is a separate field. If every element in an array field is significant, you can use one of the Arrays.hashCode methods added in release 1.5.
- Combine the hashcode c into result as follows: result = 31 * result + c;
if(string.isEmpty()){
//code
}
public abstract class Robot {
protected static Class loaded;
public static int main(String[] args) {
System.out.println(loaded);
}
}
public class Send extends Robot {
static {
loaded = loaded == null ? Send.class : loaded;
}
}