aspose file tools*
The moose likes Beginning Java and the fly likes null variable casting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "null variable casting " Watch "null variable casting " New topic
Author

null variable casting

deenbandhu prasad
Greenhorn

Joined: Feb 21, 2008
Posts: 9
public class Test1{
static void method(Object obj){
System.out.println("Object");
}
static void method(String str){
System.out.println("String");
}
public static void main(String args[]){
method(null);
}
}

The output of above program is "String". Can some one explain how is java is handling "null" variable and casting is to String and not object.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I think this FAQ will help you.


[My Blog]
All roads lead to JavaRanch
deenbandhu prasad
Greenhorn

Joined: Feb 21, 2008
Posts: 9
Thanks a ton.. it did helped.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: null variable casting