Int... A inside the ... Represents a mutable parameter, which means that this is an array of indefinite length
instanceof:
The instanceof keyword is used to determine whether an object that a reference type variable points to is an instance of a class (or interface, abstract class, parent class). As an example: PublicInterfaceIobject {
}
PublicclassFooImplementsiobject{
}
PublicclassTestextendsfoo{
}
Publicclassmultistatetest {
PublicStaticvoidMain (String args[]) {
Test ();
}
PublicStaticvoidTest () {
Iobject f=NewTest ();
if(finstanceofJava.lang.Object) System.out.println ("true");
if(finstanceofFoo) System.out.println ("true");
if(finstanceofTest) System.out.println ("true");
if(finstanceofIobject) System.out.println ("true");
}
} Output:true
true
true
trueIn addition, array types can be compared using instanceof. such as String str[] = new string[2], then str instanceof string[] will return true. 2>
Java's instanceof
When you get a reference to an object (such as a parameter), you may want to determine which class the reference really points to. So you need to start at the bottom of the tree and use the instanceof operator to judge that the first class that evaluates to TRUE is the one that the reference really points to.
For example, the following example:
Class person{}
Class Student extends person{}
Class Postgraduate extends student{}
Class animal{}
public class Instanceoftester {
public static void Main (string[] args) {
Instanceoftest (New Student ());
}
public static void Instanceoftest (person p) {
Determine the True type of P
if (P instanceof postgraduate) {
System.out.println ("P is an example of class postgraduate");
} else if (P instanceof Student) {
System.out.println ("P is an example of class student");
} else if (p instanceof person) {
System.out.println ("P is an instance of a class person");
} else if (P instanceof Object) {
System.out.println ("P is an instance of class object");
}
/*if (P instanceof Animal) {//This wrong compilation error, so make comments
System.out.println ("P is an example of Class animal");
}*/
}
}
The output of this program is: P is an instance of class student
The inheritance tree where the person class resides is: Object<--person<--student<--postgraduate.
This example also joins a animal class, which is not in the tree of the person class, so it cannot be used as the right operand of the instanceof.
Java Grammar Java did not learn, do not learn Android!