Core Java Volume I--Fundamentals, 1 by Horstmann Cay S

Core Java Volume I--Fundamentals, 1 by Horstmann Cay S

Author:Horstmann, Cay S. [Horstmann, Cay S.]
Language: eng
Format: azw3
Publisher: Pearson Education
Published: 2018-08-09T16:00:00+00:00


C++ Note

In this regard, Java generics are very different from C++ templates. C++ produces different types for each template instantiation—a phenomenon called “template code bloat.” Java does not suffer from this problem.

The raw type replaces type variables with the first bound, or Object if no bounds are given. For example, the type variable in the class Pair<T> has no explicit bounds, hence the raw type replaces T with Object. Suppose we declare a slightly different type:

Click here to view code image

public class Interval<T extends Comparable & Serializable> implements Serializable

{

private T lower;

private T upper;

. . .

public Interval(T first, T second)

{

if (first.compareTo(second) <= 0) { lower = first; upper = second; }

else { lower = second; upper = first; }

}

}

The raw type Interval looks like this:

Click here to view code image

public class Interval implements Serializable

{

private Comparable lower;

private Comparable upper;

. . .

public Interval(Comparable first, Comparable second) { . . . }

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.