Answer the question
In order to leave comments, you need to log in
What object came to me?
I have a class with a constructor that takes a Object
. I create 2 instances of this class and pass type Integer
and type Double
respectively to the constructor. How can I determine which one Object
came to me in the constructor? ( Integer
or Double
?
Answer the question
In order to leave comments, you need to log in
Use the instanceof
keyword
public MyClass(Object o){
if (o instanceof Integer) {
//Действия для Integer
}
if (o instanceof Double) {
//Действия для Double
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question