This has probably been asked before and I've seen a few similar/along the lines, but didn't quite understand it.
In Java, how do make it so a method accepts any class as a parameter?
For example,
public (AnyClass) myMethod(String whatever, (AnyClass) thisClass){
}
to be used like:
myMethod("Hello", ClassA);
myMethod("Hello", ClassB);
Thanks for any help!
Edit:
Usage example was asked for; What I'm doing is mapping a JSON string to a POJO, but trying to abstract this whole thing out so it can be reused. So - I need to be able to pass through any class, and the JSON string (or HttpConn), then build then use Jackson to build that POJO and return the object, of whatever type that may be.
(An idea of what I want to do):
public Class<?> doSomething(String jsonString, Class<?> clazz){
clazz newInstance = mapper.readValue(jsonString, clazz);
return clazz;
}
called like:
ClassA test = doSomething("String One", ClassA.class);
ClassB testTwo = doSomething("Different format string", ClassB.class);
Hope that helps understanding of the problem... and my understanding of the solutions!