Q:

Is it a bad idea to use object type(Long) as a parameter type?

Say, the function setX is defined as follows:
public void setX(Long l) {
   .....
   .....
}

If the function is called with null value in parameter, then what would happen? Will it caused NPE exception if we are doing auto unboxing somewhere in the function?
Can we say safely as a practice thats its a bad practice to use Long as the parameter to a function and instead one should always use the long?

A:

If you auto-unbox the Long into long without checking for null, you will get NullPointerException.
Using a Long instead of long makes sense if your method handles null values passed to it. If you never intend to pass null, you should use long.
And if you are using Java 8 or higher, you can also use OptionalLong.
If your method is a setter (i.e. sets the value of some instance variable), as implied by the setX name, it would only make sense for the argument to a Long if the corresponding instance variable is also Long (assuming it is allowed to be null).

