tags:

views:

84

answers:

3

Why does this not work?

    if ((List)query.execute().size() > 0)

Since execute() returns a List, I thought I could call the size() method on it?

+5  A: 

You're casting the result of the size() method to a List.

Instead, try this:

if ( ((List) query.execute()) .size() > 0)

Edit: And yea, as Adeel says: Why are you casting it in the first place? Does execute() return an Object? Otherwise, you can just lose the cast.

Henning
+5  A: 

You need brackets to indicate what you're casting. Currently you are trying to cast the result of size() to a List.

Try

(((List)query.execute()).size() > 0)
Qwerky
@Me Bah too slow!
Qwerky
Still, you added an explanation. That's better imho (+1)
seanizer
+1  A: 

I don't get the idea of casting a List to List in the first place. Secondly, Henning and Qwerky are good in suggesting that.

My take is actually, to suggest you that its better to have the list into some variable. Because here, its quite likely IMO, that you need to use the list later in your code. If you are pretty sure you wouldn't, plase go ahead with these suggestions.

Adeel Ansari