Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRay Wai
2,355 PointsWhy is there a difference between false & !true ?
Hi,
On the exercise where we are asked to validate the member variable naming, when I put
char secondLetter = fieldName.charAt(1);
if (Character.isUpperCase(secondLetter) = false) {
throw new IllegalArgumentException("Second letter must be uppercased")
}
It has a compiler error saying
./TeacherAssistant.java:12: error: unexpected type
if (Character.isUpperCase(second) = false) {
^
required: variable
found: value
1 error
But if I put
char secondLetter = fieldName.charAt(1);
if (Character.isUpperCase(secondLetter) != true) {
throw new IllegalArgumentException("Second letter must be uppercased")
}
Everything works just fine and challenge is completed, but I do not see any difference between the two. What is going on?
Ray
Ray Wai
2,355 PointsThey mean the same thing
1 Answer
Dane Parchment
Treehouse Moderator 11,077 PointsThe error you are getting is not actually in reference to the fact that you put false instead of != true, in fact I am pretty sure that there is not difference.
The error you are receiving is the fact that you are assigning the variable to the value false in the conditional instead of testing for whether the value is false or not.
In the conditional you should be doing this:
if(value == false) {
//...do something
}
//or
if(value != true) {
//... do something
}
Hopefully this answers your question.
Ray Wai
2,355 PointsDane,
Yes, this indeed answers my question, thank you!
Konrad Pilch
2,435 PointsKonrad Pilch
2,435 PointsDo you kno what !false means and what true means?