in C# when I want to know if an object is an instance of a particular type or not, I can use "is" operator:
String foo = "hi :)"
if (foo is String) ...
how can I do it in java? (I know I can use try statement, any other way?)
in C# when I want to know if an object is an instance of a particular type or not, I can use "is" operator:
String foo = "hi :)"
if (foo is String) ...
how can I do it in java? (I know I can use try statement, any other way?)
You'd use
instanceof
- that's the equivalent ofis
in C#. Note that there's no equivalent ofas
.See the JLS section 15.20.2 for more details of
instanceof
, but it's basically the same asis
:instanceof
is the java equivalent to the C#is
operator.Java equivalent:
Try something like this:-
In java you can use "instanceof" instead of "is"
I believe is what you're looking for