Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6121235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:45:41+00:00 2026-05-23T15:45:41+00:00

How do you pass a class type as parameter? public Configuration getConfig(Object mapper, Object

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:45:42+00:00Added an answer on May 23, 2026 at 3:45 pm

    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.

     conf.setClass("mapreduce.map.class",mapper.getClass(), Mapper.class);
     conf.setClass("mapreduce.inputformat.class",format.getClass(),InputFormat.class);
    

    So, if your mapper method parameter is actually an instance of TestMapper , mapper.getClass() will return the same object as TestMapper.class does.

    If your mapper and parameter already is the .class objects, i.e. you have called the method as foo.getConfig(TestMapper.class,DatastoreInputFormat.class); you can cast your Objects back to a Class object, assuming the conf.setClass() takes Class<?> type:

    conf.setClass("mapreduce.map.class",(Class<?>)mapper, Mapper.class);
    conf.setClass("mapreduce.inputformat.class",(Class<?>)format,InputFormat.class);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that if you pass a Class type as a parameter for a
I get this warning from GCC: warning: cannot pass objects of non-POD type 'class
How do I grab the Type of the inherited class and pass it into
How can I pass a parameter to a Java method with a raw type
Is it possible to pass a list constructor parameter when resolving a type? I
I have a class hierarchy, this one: type TMatrix = class protected //... public
In Java I have two classes: Class A { public String ID; public Object
I have an object that takes in a parameter of the same type in
I have a question involving calling a class's generic method with a type parameter
If I have Python code class A(): pass class B(): pass class C(A, B):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.