<T extends Drawable & DrawerToggle> ActionBarDrawerToggle(
Activity activity,
Toolbar toolbar,
DrawerLayout drawerLayout,
T slider,
@StringRes int openDrawerContentDescRes,
@StringRes int closeDrawerContentDescRes) {
During browsing source code of the class ActionBarDrawerToggle.java, I've found this constructor is declared without access specifier. Rather, its declaration starts with
<T extends Drawable & DrawerToggle>
Please explain, what does it really mean?
In addition to simple drawing, Drawable provides a number of generic mechanisms for its client to interact with what is being drawn: The setBounds(Rect) method must be called to tell the Drawable where it is drawn and how large it should be.
A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon . There are several different types of drawables: Bitmap File.
Classic drawable resources such as images are stored in the drawable folder. In contrast, vector drawables are stored in drawable-v24 . For this project, keep the drawable default and click OK. You should now see the New File dialog box.
There are two ways to define and instantiate a Drawable besides using the class constructors: Inflate an image resource (a bitmap file) saved in your project. Inflate an XML resource that defines the drawable properties.
T
is generic type declaration which is then used as a type for one of the arguments - slider
.
<T extends Drawable & DrawerToggle >
specifically means that T
must extend/implement both Drawable
and DrawerToggle
classes/interfaces.
The access specifier is not mandatory. In case it's missing it means the class/method is accessible only from classes within the same package.
Like normal methods, constructors can take type parameters. This is mentioned in this section of the Java Language Specification:
https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.8
From the syntax mentioned there, you can have type parameters in the signature:
TypeParameters:
<
TypeParameterList
>
TypeParameterList:
TypeParameter {, TypeParameter}
and where TypeParameter is specified as
TypeParameter:
{TypeParameterModifier} Identifier [TypeBound]
TypeParameterModifier:
Annotation
TypeBound:
extends
TypeVariable
extends
ClassOrInterfaceType {AdditionalBound}
AdditionalBound:
&
InterfaceType
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With