I would like to know how to execute method, in java, whenever object is created.
for example:
public class Person {
private String name;
private int age;
private Date dateCreated;
public setName(String name){
...
}
... some other methods ...
public setDateCreated(){
this.dateCreated = new Date();
}
I would really like for my setDateCreated() method to be executed on every object when it is created.
You realize, of course, that this class breaks the Java Bean standard as coded.
The standard will expect to see a Date object passed to the
setDateCreated()method:You’re free to do it your way, once you add a void return type, but don’t be shocked if other code that expects you to conform to the standard complains.