Two Laptop Bag*
The moose likes Groovy and the fly likes Another instanceof type question. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Another instanceof type question." Watch "Another instanceof type question." New topic

Another instanceof type question.

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17249

OK, I still need that other thread answered for one of my validations.

But for this other one here, It is different I am actually putting in String with instance of so (fieldValue instanceof String)

But what is odd, I have this if statement that is always returning as true, even when it should be false.

So that if is evaluating as true even when fieldValue is of type String. That part should be false.

Can't figure out what I am missing here.



Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299

This works for me with Groovy 2.0.5

GenRocket - Experts at Building Test Data
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17249

Gregg Bolinger wrote:This works for me with Groovy 2.0.5

So that wouldn't print W00t because it is of type String. Which is what I want.

To get around this I have to break the if statement into two separate ones.

And then it works the way I wanted and expected. Thanks for the replies.

I agree. Here's the link:
subject: Another instanceof type question.
Similar Threads
Shift Operator Gurus !!
instanceof operator
Trying to emulate HTTP file upload with an applet
Problem with instanceof
instanceof, but have a reference to Class