Java Reference
In-Depth Information
java.io.Serializable > 1 Object[]
• If P is a primitive type, then:
Object > 1 P []
Cloneable > 1 P []
java.io.Serializable > 1 P []
4.11. Where Types Are Used
Types are used when they appear in declarations or in certain expressions.
Example 4.11-1. Usage of a Type
Click here to view code image
import java.util.Random;
import java.util.Collection;
import java.util.ArrayList;
class MiscMath<T extends Number> {
int divisor;
MiscMath(int divisor) { this.divisor = divisor; }
float ratio(long l) {
try {
l /= divisor;
} catch (Exception e) {
if (e instanceof ArithmeticException)
l = Long.MAX_VALUE;
else
l = 0;
}
return (float)l;
}
double gausser() {
Random r = new Random();
double[] val = new double[2];
val[0] = r.nextGaussian();
val[1] = r.nextGaussian();
return (val[0] + val[1]) / 2;
}
Collection<Number> fromArray(Number[] na) {
Collection<Number> cn = new ArrayList<Number>();
for (Number n : na) cn.add(n);
return cn;
}
<S> void loop(S s) { this.<S>loop(s); }
Search WWH ::




Custom Search