How do you pass a class type as parameter?
public Configuration getConfig(Object mapper, Object format) {
Configuration conf = new Configuration(false);
conf.setClass("mapreduce.map.class", TestMapper.class, Mapper.class);
conf.setClass("mapreduce.inputformat.class", DatastoreInputFormat.class, InputFormat.class);
return conf;
}
I want to replace the value TestMapper.class and DatastoreInputFormat.class with the parameters mapper and format, respectively.
I’m not sure how to convert from Object to TestMapper.class.
The parameters to getConfig() should perhaps have Class type in in the first place instead of Object’s. However:
If you want the runtime class of whatever your mapper and format Objects are, just call their .getClass() methods.
So, if your
mappermethod parameter is actually an instance of TestMapper , mapper.getClass() will return the same object as TestMapper.class does.If your
mapperandparameteralready is the .class objects, i.e. you have called the method asfoo.getConfig(TestMapper.class,DatastoreInputFormat.class);you can cast your Objects back to a Class object, assuming the conf.setClass() takesClass<?>type: