Background:
I am working on a resource extensive operation and reinitialising the object is too costly operation. So the current implementation involves following steps
Initialisation -> Usage -> Cleanup
Say my code is something like
public class A {
public A(){
//perform resource extensive operations
}
public A performTask(){
//task performed
return this;
}
public void saveChanges(){
//perform commits and save changes
//cleanup resource
//perform other minor tasks
}
}
Requirement:
Now how to inform the person using this class to call saveChanges()
method after calling performTask()
. Please note that performTask()
is a dummy reference in this example, and in actual code it can be called multiple times.
Best example for my use case Android Shared Preference Editor. If I don't call commit()
or apply()
after calling edit()
I get a warning like below
SharedPreferences.edit() called without a corresponding commit() or apply()
So how can I create a warning something like above, To make sure saveChanges()
is called after performTask()
?