You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, equality semantics for Atoms is defined in this way:
Atom-typed fields are always compared by equals
NotAtom-typed fields are compared by reference, if indeed referenced to NotAtoms
However, in some rare cases, comparison of NonAtoms by reference may be inconvenient for some types. Consider this class:
@NotAtom
class CachedScanner {
private final String string;
private Scanner scanner;
public CachedScanner(final String string) {
this.string = string;
}
public final synchronized Scanner getOrProduceScanner() {
if(scanner == null) {
scanner = new Scanner(
new ByteArrayInputStream(string.getBytes())
);
}
return scanner;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final CachedScanner that = (CachedScanner) o;
return string != null ? string.equals(that.string) : that.string == null;
}
@Override
public int hashCode() {
return string != null ? string.hashCode() : 0;
}
}
It is mutable, so it is not Atom. However, it clearly defines equality logic, and equality logic is not tied to mutable state, so it is rather safe to rely on it. The task is to give developer the possibility to specify such exclusions from the rule.
The text was updated successfully, but these errors were encountered:
Currently, equality semantics for Atoms is defined in this way:
equals
However, in some rare cases, comparison of NonAtoms by reference may be inconvenient for some types. Consider this class:
It is mutable, so it is not Atom. However, it clearly defines equality logic, and equality logic is not tied to mutable state, so it is rather safe to rely on it. The task is to give developer the possibility to specify such exclusions from the rule.
The text was updated successfully, but these errors were encountered: