aspose file tools
The moose likes Ranch Office and the fly likes Rules Round Up #127 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » This Site » Ranch Office
Reply Bookmark "Rules Round Up #127" Watch "Rules Round Up #127" New topic
Author

Rules Round Up #127

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Saw an error of the form:
if(something = somethingelse)
which won't compile.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6913
"wek",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.

A Convergent Visionary ~ Frank's Punchbarrel Blog ~ LinkedIn profile
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6913
If you wish to compare two things, you should use == instead of = (which is an assignment operator).
Matts Smith
Ranch Hand

Joined: Feb 03, 2001
Posts: 113
Technicalities again... I had to say it
boolean b = false;
if (b = true)
{
System.out.println("I will be printed");
}
later


-------------------<br />Sun Certified Java Programmer
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6913
So yes, that will compile, and it will be printed, but it's not comparing two things. It's assigning true to b, and then self-checking the expression 'b'. What was your point exactly?
Matts Smith
Ranch Hand

Joined: Feb 03, 2001
Posts: 113

if(something = somethingelse)
which won't compile.

I was just pointing out it is possibly a boolean assignment.
 
 
subject: Rules Round Up #127
 
IntelliJ Java IDE