I have a Java method which has to accept generic object.
public <T> void myMethod(T anyClassObject) {
//handle code
}
My need is to create a method which will accept any class's instance. And then I have to save the object in database. actually I have to write a application which will make more easy the mongoTemplate API.
In my application user does not need to configure mongoTemplate. It all will be in my application. Users can simply use my code.
So for saving into database, have to specify the persistent entity class as usual.
For example,
mongoTemplate.createCollection(One.class)
For an other entity,
mongoTemplate.createCollection(Two.class)
like the above.
I have to write a method which can be accessed in common like
One one = new One();
createTable(one)
or
Two two = new Two();
createTable(two)
Would like to do it with generics.