O'Reilly logo

The Java® Language Specification, Java SE 7 Edition, Fourth Edition by Alex Buckley, Gilad Bracha, Guy Steele, Bill Joy, James Gosling

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

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] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required