Consider a method with objects as parameters. Is it a good practice to check object as not null within method or should I check it before calling that method. I am feeling that if someone is using the method later, if they pass null for a parameter, the method will fail to convey what it is missing. Please suggest the best one from the below methods.
Method 1:
void method(Object obj1, Object obj2)
{
if(obj1!=null && obj2!=null
{}
}
Method 2:
void method(Object obj1, Object obj2)
{
//logic
}
Method 3:
void method(Object obj1, Object obj2)
{
if(obj1 ! =null && obj2 !=null)
{//logic}
throw exception();
}