For example
g(s.charAt(i)); g(s.charAt(i));
is always equivalent (regardless of g
) to:
final char c = s.charAt(i); g(c); g(c);
Therefore, charAt
is referentially transparent.
Bad news; new
is a side-effect. Ever wanted to hide that constructor for your immutable type?
More bad news; Java makes it extremely difficult to be rid of impurity.[6]