Skip to content

Commit 8adc49a

Browse files
authored
Merge pull request #320 from habibasorour/issue_312_listing
Issue 312 fixed: listing in 6.5
2 parents 984b03b + cfcccbd commit 8adc49a

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

source/ch6_definingclasses.ptx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -782,11 +782,11 @@ public void test(Number a, Number b) {
782782

783783
<p>
784784
The <c>Comparable</c> interface says that any object that claims to be <c>Comparable</c> must implement the <c>compareTo</c> method.
785-
Here is an excerpt from <url href="https://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html#compareTo(T)" visual="https://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html#compareTo(T)">the official documentation</url> for the <c>compareTo</c> method as specified by the <c>Comparable</c> interface.
785+
Here is an excerpt from <url href="https://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html#compareTo(T)" visual="https://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html#compareTo(T)">the official documentation</url> for the <c>compareTo</c> method as specified by the <c>Comparable</c> interface. <xref ref="java-comparable" text="type-global"/> shows the excerpt.
786786
</p>
787787

788-
789-
<program xml:id="java-comparable" language="text">
788+
<listing xml:id="java-comparable">
789+
<program language="text">
790790
<code>
791791
int compareTo(T o)
792792
Compares this object with the specified object for order. Returns a
@@ -798,27 +798,29 @@ iff y.compareTo(x) throws an exception.)
798798
...
799799
</code>
800800
</program>
801+
</listing>
801802

802803
<p>
803-
To make our <c>Fraction</c> class <c>Comparable</c> we must modify the class declaration line as follows:
804+
To make our <c>Fraction</c> class <c>Comparable</c> we must modify the class declaration line as shown in <xref ref="java-make-comparable" text="type-global"/>.
804805
</p>
805806

806-
807-
<program xml:id="java-make-comparable" language="java">
807+
<listing xml:id="java-make-comparable">
808+
<program language="java">
808809
<code>
809810
public class Fraction extends Number implements Comparable&lt;Fraction&gt; { // fraction class is a child of Number and implements the Comparable interface
810811
...
811812
}
812813
</code>
813814
</program>
815+
</listing>
814816

815817
<p>
816818
The specification <c>Comparable&lt;Fraction&gt;</c> makes it clear that <c>Fraction</c> is only comparable with another <c>Fraction</c>.
817-
The <c>compareTo</c> method could be implemented as follows:
819+
The <c>compareTo</c> method could be implemented as shown in <xref ref="java-compare-to" text="type-global"/>.
818820
</p>
819821

820-
821-
<program xml:id="java-comparable2" language="java">
822+
<listing xml:id="java-compare-to">
823+
<program language="java">
822824
<code>
823825
public int compareTo(Fraction other) { // compare this fraction with another fraction
824826
Integer num1 = this.numerator * other.getDenominator();
@@ -827,8 +829,11 @@ public int compareTo(Fraction other) { // compare this fraction with another fra
827829
}
828830
</code>
829831
</program>
832+
</listing>
833+
830834
</section>
831835

836+
832837
<section xml:id="static-member-variables">
833838
<title>Static member variables</title>
834839

0 commit comments

Comments
 (0)