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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:09:53+00:00 2026-06-14T16:09:53+00:00

interface A { String n(); } class B implements A { @Override public String

  • 0
interface A {
    String n();
}
class B implements A {
    @Override
    public String n() { return "asdf"; }
}
interface C<T extends A> {
    T m(T t);
}
class D implements C<B> {
    @Override
    public B m(B b) {
        return b;
    }
}

Class<C<? extends A>> x = D.class;

there is an error on the last line

Type mismatch: cannot convert from Class<D> to Class<C<? extends A>>

this looks perfectly fine to me, but maybe i am missing some subtlety on how type wildcards work. Is there a way i can change the type on the last line? i need this reference because i plan on doing this later:

B b = new B();
A y = x.newInstance().m(b);

this also has an error

The method m(capture#1-of ? extends A) in the type C<capture#1-of ? extends A> is not applicable for the arguments (B)

however, if i use it without the wildcards and capture, it works fine:

A z = D.class.newInstance().m(b);

unfortunately im kinda stuck with this for now, any help would be appreciated.

edit: removed this. references

edit: changed x to be

Class<? extends C<? extends A>> x = D.class;

and it works. however still getting errors on x.newInstance().m(b)

The method m(capture#2-of ? extends A) in the type Test.C<capture#2-of ? extends A> is not applicable for the arguments (B)
  • 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-06-14T16:09:55+00:00Added an answer on June 14, 2026 at 4:09 pm

    Right, focusing just on the last part:

    however still getting errors on x.newInstance().m(b)

    The method m(capture#2-of ? extends A) in the type
    Test.C<capture#2-of ? extends A is not applicable for the arguments (B)
    

    Indeed – and that makes perfect sense. Because nothing in your code indicates that you’ve actually got a C<B>. All the compiler knows is that newInstance has returned an instance of some type which implements C<X> for some type X which implements A. How would it know that that’s B?

    If you want to call m(b), you’ll need a C<B>, which means that your declaration would need to be

    Class<? extends C<B>> x = D.class;
    

    At that point, the method invocation compiles cleanly. It’s not really clear what you’re trying to achieve, or whether this will be good enough for you – but hopefully it explains why you’re getting the error you’re getting…

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

Sidebar

Related Questions

interface i1{ int test(); } interface i2{ String test(); } class Test implements i1,i2{
Given the following interface and implementation class: public interface MyInterface { public String getSomething
I have the following Java class: public class GetCardInfoRequest implements RequestBase, java.io.Serializable{ public String
The code: interface Property<T> { T get(); } class BoolProperty implements Property<Boolean> { @Override
Given the following classes and interfaces class A{ @NotNull(groups=Section1.class) private String myString } interface
I have interface IConfigurationSource { .... } and class FileConfigurationSource : IConfigurationSource { FileConfigurationSource(string
I have next interface public interface IMyInterface { string this[string key] { get; set;
Lets create some interfaces public interface ITimeEventHandler { string Open(); } public interface IJobTimeEventHandler
Say I have the following: namespace SomeProject { public interface ISomething { string SomeMethod();
Currently i have some interfaces (stripped down for here): public interface IJobGroup { string

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.