aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assertion issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Assertion issue" Watch "Assertion issue" New topic
Author

Assertion issue

Ajit Sawant
Ranch Hand

Joined: Nov 26, 2008
Posts: 33
Hello,

public class Testassert{
public static void main (String [] args){
System.out.println("before assert " +args[0]);
assert (args[0]== "y");
System.out.println("after assert " +args[0]);
}
}
For the program, I am always getting assertion error java.lang.AssertionError.I expect to see that error only when somthing other than "y" is passed as an argument to the program.
java -ea Testassert y --- should not give any error
java -ea Testassert x --- should give the error

Thanks,
Ajit
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

How do you compare strings in Java ?


[My Blog]
All roads lead to JavaRanch
Ajit Sawant
Ranch Hand

Joined: Nov 26, 2008
Posts: 33
I corrected it to args[0].equals("y"). Now it works.
Thanks for making me to think.
Ajit
Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
I think it is not good to use Assertions to validate Command-line arguments....


SCJP5 and SCWCD1.5
Think Twice Act Wise...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Assertion issue