add()
is invoked one time, ten times, or a million times with a given value for a
and b
, the result of add()
will never change. However, consider the following function:add()
is no longer an idempotent function. Every time it is invoked, it changes the value of the sum
variable and returns it. Invoking it with the same value of b
multiple times will return a different result each time.Date
constructor here implicitly uses the current system time at the millisecond precision for getting the current date. If we invoke this function multiple times with the same input value for days
, the returned Date
instance will still be different every millisecond.Date
class before might be aware that the actual time of the Date
can be changed via the setTime(Long)
method.addDaysToDate
function mutable. This will generally be a problem in multi-threaded environments if the date
instance being passed to the addDaysToDate
method is modified from another thread while the addDaysToDate
method is executing.addDaysToCurrentDate
function, it gets the current date implicitly by creating a new Date
instance which internally uses the System.currentTimeMillis()
call to get the current timestamp.