On Mon, 8 Jul 2024 18:04:49 GMT, Alan Bateman <al...@openjdk.org> wrote:
> Specifying that toString returns a non-null result is good. Specifying that > the methods don't throw any exceptions, or an implSpec that the methods > shouldn't throw is okay. > > I'm less sure about the proposed wording for resource usage. For hashCode > then maybe it should say that the hashCode method may be called very > frequently and should be as fast and use as few resources as possible. Some additional background that I didn't try to put into the guidance, there are certainly contexts where calling the `toString()` or `hashCode()` methods on possibly-not-trusted objects is ill-advised. When you need a string or hash code for an object in those situations, `System.identityHashCode` and `Objects.toIdentityString` can be used. However, I think in many other contexts, and even the default context, you want to be able to call `toString` and `hashCode` on the objects you're using and have them give sensible results. The intention of this change is to make that expectation of usability explicit. ------------- PR Comment: https://git.openjdk.org/jdk/pull/20063#issuecomment-2215233823