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

  • Home
  • SEARCH
  • 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 6624593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:40:21+00:00 2026-05-25T21:40:21+00:00

See the bottom for the solution. I’m trying to write some generic handling code,

  • 0

See the bottom for the solution.

I’m trying to write some generic handling code, but in 1 of the sub-classes, it requires a Class that is more specific.

So the base class as a field of type Class, and in the subclass I’m trying to cast that Class object to type Class which is a subclass of org.​apache.​hadoop.​hbase.​mapreduce.Mapper.

I get the following error from Netbeans:

"Incompatible types
required: java.lang.Class<org.apache.hadoop.hbase.mapreduce.TableMapper>
found: java.lang.class<capture#3 of ? extends org.apache.hadoop.mapreduce.Mapper>"

when I try the following code

Class<TableMapper> tableMapperClass = null;
if( mapperClass.equals(TableMapper.class) ) {
    tableMapperClass = TableMapper.class.asSubclass(mapperClass);

    //do stuff
}

and I get:

incompatible types
required: java.lang.Class<org.apache.hadoop.hbase.mapreduce.TableMapper>
found: java.lang.Class<capture#8 of ? extends org.apache.hadoop.hbase.mapreduce.TableMapper>

for

Class<TableMapper> tableMapperClass = null;
if( mapperClass.equals(TableMapper.class) ) {
    tableMapperClass = mapperClass.asSubclass(TableMapper.class);

    //do stuff
}

Ok, got the answer from my co-worker, looks like this should work:

Class<? extends TableMapper> tableMapperClass = null;
if( mapperClass.equals(TableMapper.class) ) {
    tableMapperClass = mapperClass.asSubclass(TableMapper.class);

    //do stuff
}
  • 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-25T21:40:21+00:00Added an answer on May 25, 2026 at 9:40 pm

    If you want to assign a class to tableMapperClass that is actually a subclass of TableMapper, then you need to change the type of the variable. Instead, use:

    Class<? extends TableMapper> tableMapperClass = null;
    

    and now you can assign TableMapper.class or any subclass to this variable. When you write Class<TableMapper> you are promising that the variable will be exactly TableMapper.class or null.

    Another example:

    Class<Number> number = Integer.class; // does not compile
    Number number = new Integer(1); // compiles fine
    Class<? extends Number> number = Integer.class; // also ok
    

    Note that you can do different things with Class<Number> then you can with Class<? extends Number>. For example, you can call a constructor of Class<Number>, because you know the class. You can’t do that with Class<? extends Number> because the constructors are not defined at compile time.

    Similarly with, say, List<Number> vs List<? extends Number>. You can call list.add(7) on a variable of type List<Number>, but you can’t do that on a List<? extends Number> because you don’t know the type of the second list. It might be a List<Double> for example, in which case adding an Integer is not allowed.

    Generics are weird. 🙂 Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(resolved: see bottom) I have the following code snippet: Protected Sub SqlDataSource1_Inserted(ByVal sender As
Fixed: See notes at bottom I am implementing a generic class that supports two
EDIT: Sorted. See bottom for solution Okay, I have to write a program that
Intro: EDIT: See solution at the bottom of this question (c++) I have a
See the solution at the bottom of the question. IE 8 (and lower) does
Must be simple solution. But I do not see it. Please help me. Looks
Update: This issue is caused by bad memory usage, see solution at the bottom.
(If your lazy see bottom for TL;DR ) Hello, I am planning to build
If I reference the SnakeYAML jar directly from a test program (see bottom), everything
Sorry for a pretty specific question. I have a table (see bottom), and when

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.