Learn Java Programming - Generics: Bounded Type Parameters Tutorial

Veröffentlicht am: 20 September 2015
auf dem Kanal: Daniel Ross
6,984
64

In this tutorial I will introduce you to bounded type parameters. I will expand on my example Box class by turning it into a generic class that will take values from various types of classes that are subclasses of the Number class. Classes such as Integer, Float, Double, etc. will all be valid parameter types for this new and improved version. Bounded type parameters limit the valid type parameters to only types that are an instance of the bounded type. The Java keywords extends is used to specify the bounded type.
For example,
class Box<T extends Number&rt; { ... }
In the example above, the Number class is the bounded type specified after the extends keyword. The T is the type-variable. The T type-variable must be a subclass of Number somewhere down the hierarchy or else a compiler error will occur. Angle brackets are also known as chevrons or diamond syntax.


Auf dieser Seite können Sie das Online-Video Learn Java Programming - Generics: Bounded Type Parameters Tutorial mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Daniel Ross 20 September 2015 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 6,984 Mal angesehen und es wurde von 64 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!