Java Reference
In-Depth Information
20 GenericMatrix.printResult(
21 m1, m2, rationalMatrix.multiplyMatrix(m1, m2),
'*'
);
22 }
23 }
multiply two matrices
m1 + m2 is
1/5 1/6 1/7 1/6 1/7 1/8 11/30 13/42 15/56
2/5 1/3 2/7 + 1/3 2/7 1/4 = 11/15 13/21 15/28
3/5 1/2 3/7 1/2 3/7 3/8 11/10 13/14 45/56
m1 * m2 is
1/5 1/6 1/7 1/6 1/7 1/8 101/630 101/735 101/840
2/5 1/3 2/7 * 1/3 2/7 1/4 = 101/315 202/735 101/420
3/5 1/2 3/7 1/2 3/7 3/8 101/210 101/245 101/280
19.23
✓
✓
Why are the
add
,
multiple
, and
zero
methods defined abstract in the
GenericMatrix
class?
Check
Point
19.24
How are the
add
,
multiple
, and
zero
methods implemented in the
IntegerMatrix
class?
19.25
How are the
add
,
multiple
, and
zero
methods implemented in the
RationalMatrix
class?
19.26
What would be wrong if the
printResult
method defined as follows?
public static void
printResult(
E[][] m1, E[][] m2, E[][] m3,
char
op)
K
EY
T
ERMS
actual concrete type
738
generic instantiation
738
bounded generic type
743
lower-bound wildcard
(
<? super E>
)
bounded wildcard
(
<? extends E>
)
748
748
raw type 746
unbounded wildcard (
<?>
)
formal generic type
738
748
C
HAPTER
S
UMMARY
1.
Generics
give you the capability to parameterize types. You can define a class or a
method with generic types, which the compiler replaces with concrete types.
2.
The key benefit of generics is to enable errors to be detected at compile time rather than
at runtime.
3.
A generic class or method permits you to specify allowable types of objects that the
class or method can work with. If you attempt to use a class or method with an incom-
patible object, the compiler will detect the error.
4.
A generic type defined in a class, interface, or a static method is called a
formal generic
type
, which can be replaced later with an
actual concrete type
. Replacing a generic type
is called a
generic instantiation
.
Search WWH ::
Custom Search