• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why is it not posible to use if(input.equals("bye") .toLowerCase() .trim())  RSS feed

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is it not posible to use if(input.equals("bye").toLowerCase().trim()), error msg is "boolean cannot be dereferenced"
What is meant by "boolean can not be dereferenced"

Varuna
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What form is "input?" The usual reason for that error is that you have put a primitive before a . operator. Make sure "input" is a String. And see this old thread where Robin Lane had a similar problem.
 
Varuna Seneviratna
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is the whole block concerned. input is a String
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you've got a closing bracket in the wrong place. You are trying to call toLowercase on the return value of input.equals() which is a boolean.
Try
I'm assuming this is just an example of your problem because "bye" is already lowercase and trimmed so you don't need to call those methods anyway.

Edit
Or did you really want
[ December 04, 2008: Message edited by: Joanne Neal ]
 
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if(input.equals("bye").toLowerCase().trim())

as far as i understood ,
input.equals("bye") would return true or false.
So once that part of the statement is executed( lets assume it returns true) it would be somthing like
if(true.toLowerCase().trim())
now we are sure why the error is inevitable.
Correct me if i am wrong.
 
Varuna Seneviratna
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by James Tharakan:
if(input.equals("bye").toLowerCase().trim())

as far as i understood ,
input.equals("bye") would return true or false.
So once that part of the statement is executed( lets assume it returns true) it would be somthing like
if(true.toLowerCase().trim())
now we are sure why the error is inevitable.
Correct me if i am wrong.


You are right James, When I changed the method calling order to it works.So what I gather from this is the processing precedence is from Left to Right

Varuna
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good,and you got the right information
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would change one little thing in that line of code:

toLowerCase() may create a new String object, something you can avoid by using a simple method call.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!