Questions tagged [instanceof]

instanceof is an operator available in some object-oriented languages, including Java, php and JavaScript. Generally speaking, it allows the programmer to check whether an object passed as its left operand is an instance of a class specified by the right operand.

instanceof is an operator available in some object-oriented languages, including Java, php and JavaScript. It allows the programmer to check whether an object passed as its left operand is an instance of a class specified by the right operand.

instanceof in Java

instanceof in php

instanceof in JavaScript

958 questions
-3
votes
2 answers

validate string with a quoted type like "String", "Boolean" in Java

I have a scenario where i need to use "Test String" instanceof "String" is anyway i can do that in java? The requirement is validate string with a quoted type like "String", "Boolean"
-3
votes
1 answer

Checking if Generic Class is instanceof Abstract Class

public static void main(String[] args) { Class b = B.class; System.out.println(b.isAssignableFrom(A.class)); } static abstract class A{ } static class B extends A{ } Output: false The output is false I try to use instanceof and it has…
joseph lake
  • 53
  • 1
  • 7
-3
votes
2 answers

What is the difference between number and Number in javascript?

The output of: var x = 5; typeof (x) //will give number type as output But for the below code it returns false: var x = 5; x instanceof Number; //will give false as output Can anybody please explain the difference between number and Number. And…
Azan Momin
  • 121
  • 1
  • 2
  • 10
-3
votes
1 answer

How do you take an object out of array and use instanceof on it?

I am trying to make the following code or something similar to work: static String[][] arr = new String[4][4]; static int[][] arr2 = new int[4][4]; for(int i = 0; i < arr.length; i++){ for (int j = 0; j < arr[0].length; j++) { …
Uio443
  • 3
  • 2
-3
votes
1 answer

using instanceof to count in java

import java.util.ArrayList; public class Folder extends AbstractFile { //Replace previous ArrayLists with a single //ArrayList of AbstractFile references private ArrayList files = new ArrayList(); AbstractFile…
John
  • 43
  • 1
  • 7
-3
votes
1 answer

JAVA: Comparing an object from another class to an object

I have in a class the following code... String processor() { Stack stack = new Stack<>(); while (curr < infixExpr.length()) { // assigning the current index position of string in infix expression to a variable to reduce amount…
-3
votes
1 answer

Does the instanceof operator consider sibling classes instance-ofs?

So, If I have four classes, A, B, C and D. Classes B and C extend class A and class D extends class C. Using Java's instanceof operator will B instanceof C return true because they have the same parent?
Eoin Moran
  • 13
  • 2
-3
votes
1 answer

object instanceof Object is false ,why?

in express on node var query = request.query; print out the info of query below: add: on mac: query instanceof Object is true but on CentOS release 6.4 (Final) : is false(images below) add again: node: 0.12.2 express: 3.4.4 OS: CentOS release…
SKing7
  • 2,204
  • 4
  • 21
  • 29
-3
votes
1 answer

Java using instanceof to check the class with same name in different packages

I have two files with same name in different packages, in certain function i need to check the argument passed is of the instanceof which class it is. Eg. if(input instanceof x.y.test) { //do something } else if(input instanceof x.y.z…
-4
votes
3 answers

What does this method work with instanceof?

i want to know how does this method works? Especially this part of code "((Book) o).getId()" public boolean equals(Object o){ if (o instanceof Book){ return id == ((Book) o).getId(); } return false; } Thank you
Vig Killa
  • 19
  • 6
-5
votes
4 answers

Object instanceof Integer returns false

Object obj = "1234"; System.out.println(obj instanceof Integer); What else should I do to check such Object if its an instanceof Integer or Float.
Muhammad Imran Tariq
  • 22,654
  • 47
  • 125
  • 190
-6
votes
1 answer

Java - interface -instsnceof

How can this be legal? A is not implemented by Intf. Therefore how could it be legal to use as this? interface Intf { } class A{ } class B{} class Test { public static void main(String[] args) { A obj = new A(); …
KNB
  • 97
  • 3
  • 9
-6
votes
2 answers

Actual class of object reference

Given three classes A, B, and C, where B is a subclass of A, and C is a subclass of B. (a) (o instanceof B) && (!(o instanceof A)) (b) (o instanceof B) && (!(o instanceof C)) (c) !((o instanceof A) || (o instanceof B)) (d) (o instanceof B) (e) (o…
paidedly
  • 1,413
  • 1
  • 13
  • 22
1 2 3
63
64