• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Assertion issue

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you compare strings in Java ?
 
Ajit Sawant
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I corrected it to args[0].equals("y"). Now it works.
Thanks for making me to think.
Ajit
 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it is not good to use Assertions to validate Command-line arguments....
 
reply
    Bookmark Topic Watch Topic
  • New Topic