13.07.2015 Views

4. Object Structures, Aliasing, and Encapsulation

4. Object Structures, Aliasing, and Encapsulation

4. Object Structures, Aliasing, and Encapsulation

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

class ImmutableList { // continued...boolean equals( <strong>Object</strong> that ) {if( that == null ||!(that instanceof ImmutableList )return false;ImmutableList tl = (ImmutableList) that;if( isempty() ) {return that.isempty();} else if( that.isempty() ) {return false;} else {return ( this.head == that.head )&& tail().equals( that.tail() );}}}2. Immutability <strong>and</strong> inheritance:There may be scenarios in which objects of typeImmutableList are not immutable:...static boolean somemethod( ImmutableList il ){if( !il.isempty() ) {return il.head() == il.head();} else return true;}13.05.13© A. Poetzsch-Heffter, TU Kaiserslautern14

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!