I recently worked on a GWT project and really enjoyed using the toolkit; in particular, it was nice to be able to practice Test Driven Development using all the handy tools available for Java such as JUnit, JMock, and the refactoring tools in IntelliJ IDEA.
There was one minor annoyance that kept causing problems; GWT's JavaScript compiler didn't provide an implementation of Object's getClass() method. In general, this wasn't a big problem, but what did cause a problem was any time you used IntelliJ's or Eclipse's "Generate equals() and hashCode()" helpers, they automatically inserted calls to getClass():
public boolean equals(Object o) {
if (this == o) return true;
// Oops, this next line uses getClass and causes GWT to crash and burn
if (o == null || getClass() != o.getClass()) return false;
Person person = (Person) o;
return ssn == person.ssn;
}
This would ultimately cause error messages like so:
[ERROR] Errors in 'F:\Dev\GwtTesting\src\com\danielwellman\client\model\Person.java'
[ERROR] Line 22: The method getClass() is undefined for the type Person
[ERROR] Line 22: The method getClass() is undefined for the type Object
Here GWT's compiler was complaining because there's no getClass() method available on Object in the JavaScript layer.
Long story short, GWT has added a simple implementation of getClass() for GWT 1.5. I downloaded the latest release candidate, generated a default equals() and hashCode(), and everything just works.
For the curious, here's a link to the issue tracker.
Thank you, GWT community and team!
Comments
You can follow this conversation by subscribing to the comment feed for this post.