• Post Reply Bookmark Topic Watch Topic
  • New Topic

working with null...  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you explain why System.out.println(.. is not efficent in those line of codes !?
...............
void provaNull(){
Object o1 = null;
Object o2 = null;
final String sf = "final";
String s,s1;
System.out.println("........"+ o1.equals(o2));
s = null;
System.out.println("String s = null;....="+s);
s1= "abcde";
if (s.equals(s1))System.out.println("equals");
else System.out.println("not equals");
s1=null;
if (s.equals(s1))System.out.println("equals ");
else System.out.println("not equals");

System.out.println("OK");

}
................
Grazie! ciao!
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
edi
What do you mean by not efficient? Could you please elaborate...
Also, your name is not in compliance witht the naming conventions here on the ranch, you can check them out here

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im going to guess that you want to know what's wrong with the the line
System.out.println("........"+ o1.equals(o2));
The problem is that you are calling the equals() method on a null object. You cannot do this.
Good luck.
 
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
edi,
Please change your name to be compliant with JavaRanch's naming policy.
Your ID should be 2 separate names with more than 1 letter each. We really want this to be a professional forum and would prefer that you use your REAL name.
Thanks,
Cindy
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!