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
-1
votes
3 answers

instanceof in java

Possible Duplicate: Java: What does the colon (:) operator do? for (CreditCard cc : credit1) & if (index instanceof RewardCard) is ":" and instanceof the same? so I could use? if (index : RewardCard) or for (CreditCard cc instanceof…
Shawn
  • 309
  • 2
  • 5
  • 11
-2
votes
2 answers

How can I get this Java instanceof test to return false rather than an error?

I have been experimenting with instanceof in my Java code. public class Test { public static void main(String[] args) { String favoriteFood = "sandwich"; boolean flag = favoriteFood instanceof StringBuilder; //incompatible types …
K Man
  • 602
  • 2
  • 9
  • 21
-2
votes
2 answers

My GUI is not recognizing my instance method. How can I fix this?

1) I can not call my instance method in the GUI 2) I can not implement a specific feature. I have two basic problems. First of all, I need my GUI to recognize my instance method (namely, when I call my isWin method in my GUI, the method is not…
-2
votes
1 answer

downcasting not working and giving error in my program

I have a class Person and a class Instructor that extends Person public class Driver { public static void main(String args[]) { Person[] array = new Person[5]; array[1] = new Person("John Doe"); array[2] = new Person("Bobby Gram"); …
-2
votes
2 answers

Java instanceof

I have a node(Gridpane node) and i want to get instanceof from class but either a node or any object i can not get instanceof of my class, i need to add something to a class to do "instanceof" or am i doing it wrong? public void Move(GridPane…
xCrazy
  • 3
  • 4
-2
votes
1 answer

Having trouble validating the type

The goal is to make a custom ArrayList. So far it's worked, however, once I try checking to ensure only the initialised type is entered into the array, I start running into problems (arrayType cannot be resolved to a type -- I am using eclipse). My…
-2
votes
2 answers

Return an object that is an instanceof a string

I am creating a Dependency Injection factory class which allows me to rewrite instances outside and inside the class without having to keep overwriting it. The issue I have is when I call the instanceof on the object referring the namespace like…
Jaquarh
  • 6,493
  • 7
  • 34
  • 86
-2
votes
3 answers

How to use instanceof operator of java here?

I'm solving this problem in Hackerrank. How can i use instanceof operator in Java to successfully compile the code? Link : https://www.hackerrank.com/challenges/java-iterator The incomplete code : import java.util.*; public class Main { static…
Swaggerboy
  • 339
  • 1
  • 2
  • 15
-2
votes
1 answer

Convert from Object to anything (conditionally)

I have a method which needs to inspect the value of an Object and determine its datatype and then converts the passed in value to the appropriate formatted java datatype. Is there a more elegant way to do this? switch? Functional? I am using…
cicit
  • 581
  • 5
  • 24
-2
votes
1 answer

Access members of case class

I have a case class defined in a scala companion object. case class ResponseSuccess(resp: SMPPSubmitSMResp) Which I send to an akka-actor (Java) if(res.isRight) sender ! Backend.ResponseSuccess(sms.resp) It is received like this, but I don't know…
FelixHJ
  • 1,071
  • 3
  • 12
  • 26
-2
votes
2 answers

Control access in methods

I have a question about Java. I have a class Say.java that has some methods, like sayHello(), saySomething(), sayBye(), ... I have other classes too. I have a class Person, and two subclasses of Person: Senior and Junior. My job to do is the…
Maik
  • 1
-2
votes
1 answer

JavaScript instanceof error

I'm trying to throw a error as a object, so that I can create a if-statement to check if a error is a emergency-error or not. For this I need to check if the error instanceof myEmergencyFunc. But this fails if I have a sub-function. See this fiddle…
user3631654
  • 1,735
  • 6
  • 22
  • 38
-2
votes
1 answer

Java: Game modding, instanceof

I'm making a "forcefield" for a game called Minecraft. What I commented on is what I need help with. if (Camb.killaura) { nchitDelay++; for(Object o: mc.theWorld.loadedEntityList){ Entity e = (Entity)o; if(e != this &&…
Brad
  • 115
  • 3
-3
votes
1 answer

Java instanceof magic

There is such a method: static void test(List list) { System.out.println(list); if (!(list instanceof ArrayList arrayList)) return; System.out.println(list == arrayList); arrayList.add("list"); …
Leonis
  • 294
  • 3
  • 10
-3
votes
1 answer

Incompatible conditional operand types double and double Java(16777232) when using instanceof

I've been working on a personal Java project which essentially is mimicking a trading common backtesting spreadsheet. Everything has been fine up until the use of multiple instanceof operators in one line. I've had a look online and to no avail have…
mghaby
  • 1
  • 2
1 2 3
63
64