Traemos la mejor solución que hallamos en línea. Deseamos que te sirva de ayuda y si deseas comentarnos alguna mejora hazlo libremente.
Ejemplo 1: java typeof
Object obj =null;
obj =newArrayList<String>();System.out.println(obj.getClass());
obj ="dummy";System.out.println(obj.getClass());
obj =4;System.out.println(obj.getClass());
Ejemplo 2: insanceof
Theinstanceof operator tests toseeif the prototype property of a constructor
appears anywhere in the prototype chain of an object. Thereturn value is a
booleanvalue.
For example :-
function Car(make, model, year)this.make = make;this.model = model;this.year = year;const auto =newCar('Honda','Accord',1998);
console.log(auto instanceofCar);// expected output: true
console.log(auto instanceofObject);// expected output: true
Ejemplo 3: Explicar el operador instanceof en java
Aninstanceof in Java is a comparison operator which, given an object instance,
checks whether that instance is of a specified type (class/sub-class/interface)
or not. Just like other comparison operators, it returns true or false.
Comparing any object instance withanull type through instanceof operator
returns a false.
Instanceof operator is used totest the object is of which type.
Syntax:<reference expression>instanceof<destination type>Instanceof returns trueif reference expression is subtype of destination type.
Instanceof returns falseif reference expression is null.
valoraciones y reseñas
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)