Incompatible types... Java

First of all sorry for posting this not in the programming forum...it seems to be dead.

Here's my problem:

// ----- Method to test for a legal menu choice
public static boolean testMenuChoice( char synMenuChoice )
{
// Allocate and prime the choice to a false state
boolean result = false;

if ( synMenuChoice = 'F')
{
result = true;
}
else
{
result = false;
}

return result;
}

------------------------------------
incompatible types
found : char
required: boolean
if ( synMenuChoice = 'F')
^
1 error

I am not certain why this is not working? can anybody help?

Thanks in advance!
-Spets
 
Oh god yeah, me too. Doing C programming at uni, make that mistake numerous times daily, still don't understand which one to use!
 
Originally posted by donbenni
Oh god yeah, me too. Doing C programming at uni, make that mistake numerous times daily, still don't understand which one to use!
Yeah the nice thing about Java is it will give you an error if you use the wrong one in the wrong place. A C program will compile, but just not run right. I'll try to explain the differnece between the two operators as best I can:

=: This is an assignment operator. It will evaluate the stuff on the right hand side, and put it in the variable on the left hand side. Note that the thing on the left but be a single variable, non-constant.

==: This is a test operator. It chech wheter the stuff on the right is equal to the stuff on the left, and evaluates to true or false. There can be complicated expression on both sides of the operator. To help with debugging, I like to wirte my if statements like if ( 5 == p ) rather than if ( p == 5 ). That way, if I accidently put in a "=" instaed of a "==", the compiler will throw an error messsage.
 
Cheers skip :) Moving onto Java in September this year so will remember that. Also continuing C prog in Sept and using it in relation to Virtual Reality :D It looks so cool!
 
Back