Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

instanceof

 
Saibabaa Pragada
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Why I am getting error at Line 7 but I don't see any issue with Line 5
 
Mohamed Sanaulla
Saloon Keeper
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the error at Line 7 may be because- Its trying to do a cast?
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a syntax errror
just remove those brackets of Short
it has nothing to do with instanceof test
 
Saibabaa Pragada
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Prasad. I do not have brackets at Line 5. That's why Line 5 is fine. But Line 7 has brackets. Please advice why I am getting error if I keep the brackets at Line 7. What is wrong with that ?
 
Thakur Sachin Singh
Ranch Hand
Posts: 242
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mainly we use () brackets for casting the variable and value...here compiler gives error "Illegal start type" because we can't use instanceof operator when we doing casting...see more code like-



here we can not use instanceof operator because this gives us syntax error.
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we write types in brackets for typecasting
here we are not casting anything and I don't think that it is valid also to use casting with instanceof operator
as instanceof will check for whole hierarchy
 
Saibabaa Pragada
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure how typecasting affects here..I used brackets in this code but do not see any issue.
 
Mohamed Sanaulla
Saloon Keeper
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My take on this:
The use of (<Type>) is usually regarded as a typecast- So once the compiler encounters this- it expects a value to be followed.
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saibabaa Pragada wrote:I am not sure how typecasting affects here..I used brackets in this code but do not see any issue.

of course there should not be any issue with brackets here
we are not typecasting here at all, this is just simple mathematics with brackets
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic