fire(Mandatory<Employee> employee);
If you had a method with this signature, you could still call fire(null)
; it'd just be that you'd have a null
of type Mandatory<Employee>
instead of type Employee
. You haven't actually improved safety at all; you've just added a redundant layer of wrapping.
If you want to enforce that a parameter is required, good practice is to use e.g. Preconditions.checkNotNull
as the first thing in your method to immediately throw a NullPointerException
if the value is null.