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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:47:34+00:00 2026-06-15T02:47:34+00:00

Ok, so I have a parametric interface whose implementation has an inner class. It

  • 0

Ok, so I have a parametric interface whose implementation has an inner class. It seems I cannot in any way reference the full (generic) type of the inner class, since it is not itself parameterized and only implicity uses the enclosing class’ type parameter:

public interface TestA<R> {
   public Class<? extends R> getTheRClass();
}

public class TestB<Z> implements TestA<TestB<Z>.InnerStuff> {

   public class InnerStuff {
       List<R> iCantBeStatic;
   }

   InnerStuff myStuff;

   @Override
   public Class<? extends TestB<Z>.InnerStuff> getTheRClass() {
      // return InnerStuff.class;
      // return myStuff.getClass();
      // return TestB.InnerStuff.class;
      // return TestB<Z>.InnerStuff.class;
      throw new AngryProgrammerException();
   }
}

Is there any way to return the class in question and have the compiler recognize the correct type?? Yes, I know there are 1,001 way to work around the problem (make the inner class static, refactor so there is no inner class, etc, etc) I’d like to know if there is an expression that works in that override, or if no such expression exists…

  • 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-15T02:47:36+00:00Added an answer on June 15, 2026 at 2:47 am

    Due to erasure, the actual Class instance that you’re returning will internally just be TestB.InnerStuff.class; the <Z> part doesn’t actually exist at run-time. So your instinct with return TestB.InnerStuff.class was on the money. To get it to work, all you need to do is add a cast to the raw-type Class to convince the compiler not to squeal:

    return (Class)TestB.InnerStuff.class;
    

    (You can then add an annotation like @SuppressWarnings({ "unchecked", "rawtypes" }) to tell your compiler that you don’t want warning-messages for this.)

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

Sidebar

Related Questions

Let's say we have a class that embed another parametric one, that has to
I have a parametric variable in a type class which I would like to
Many statically typed languages have parametric polymorphism. For example in C# one can define:
I have a parametric curve, say two vectors of doubles where the parameter is
I have a settings.php file with parametric variables and a functions.php with well, some
have written this little class, which generates a UUID every time an object of
Have done quite a bit of searching for a guide (of any substance) for
Have deployed numerous report parts which reference the same view however one of them
I have a class called CoolMenuItems class CoolMenuItems { public: CoolMenuItems(); ~CoolMenuItems(); struct MenuItemOne
I am implemented a class for Weighting scheme and have created 4 constructor in

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.