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 7701737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:03:57+00:00 2026-05-31T23:03:57+00:00

I boiled the thing I want to do to the following minimal code: public

  • 0

I boiled the thing I want to do to the following minimal code:

public class TestClass {

    class Class2Extend {
    }

    class Foo {
        public Foo(Class<Class2Extend> myClass) {

        }
    }

    class Bar extends Class2Extend{

    }

    public TestClass() {
        new Foo(Class2Extend.class); // works fine 
            //new Foo(Bar.class); -> fails even though Bar extends Class2Extend - but I want something like this to have nice code
    }
}

I can use an interface but it would be cleaner this way. Anyone can give me a hint/trick on this problem?

  • 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-31T23:03:59+00:00Added an answer on May 31, 2026 at 11:03 pm

    Change to:

    class Foo {
        public Foo(Class<? extends Class2Extend> myClass) {
    
        }
    }
    

    When you say your argument is of type Class<Class2Extend> Java matches exactly to that parameter type, not to any sub-types, you have to explicitly specify that you want any class that extends Class2Extend.

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

Sidebar

Related Questions

with the following code (a boiled-down version of my original code) #include <iostream> #include
I have a Sinatra app that, boiled down, looks basically like this: class MyApp
I'm working on some existing code. After a few hours, I've boiled this problem
I would like to reduce the following boiler plate code, BUT without using lenses
I have many entry points in my assembly and I want some initialization code
I realize this question could be boiled down to Why is my code so
I want to add a image just above the navigation bar. Here is the
I just spent hours trying to debug my code. The whole problem boiled down
Hello I am fairly new to Scala. I want to learn Scala because: To
I use socket.io version 0.8.4 I have boiled down my problem to the following.

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.