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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:58:42+00:00 2026-06-14T06:58:42+00:00

Possible Duplicate: Is it possible to reference a nested generic parameter in java? A

  • 0

Possible Duplicate:
Is it possible to reference a nested generic parameter in java?

A quick question on Java generics if I may. Is there syntax for declaring a generic class-wide type that is NOT used as a generic parameter for instantiation. For example:

public class <U extends FooUType> BarType<T extends FooType<U>>{

   public U getU(){return U;}
}

To create a BarType I want to write the following, which in itself contains U, but I don’t want to have to specify U separately. So:

BarType<SomeT<FooUType>> instance

We get the type of U implicitly from the parameterized SomeT without having to specify U separately. As opposed to :

public class BarType<U extends FooUType, T extends FooType<U>> 

which would require:

BarType<FooUType,SomeT<FooUType>>

I guess I’m looking for something akin to the same idea in methods:

public <U> boolean StupidMethod(String s){
    ...
}

I would rather not use <? extends FooUType> as this leads to problems with method return types inside the class that return <U extends FooUType> U.

Many thanks for the clarification!

  • 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-14T06:58:43+00:00Added an answer on June 14, 2026 at 6:58 am

    Thanks all,

    I went for a different solution in the end. Basically the class I was trying to hide the U in was abstract and so I added U as a generic parameter as there is no way round this. I then created the concrete classes that extend this and had them fill in the type of U silently so that the caller wouldn’t need to bloat their code.

    Something like this:

    public abstract class MyAbsClass<U extends Foo, T extends Bar<U>>{...}
    
    public class ConcreteClass<T extends SomeBar> extends MyAbsClass<SilentUType, T>
    

    where SomeBar is not parameterized. The user can then just instantiate with T:

     new ConcreteClass<SomeDerivedBar>()
    

    This worked for my scenario neatly, so I hope it helps others.

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

Sidebar

Related Questions

Possible Duplicate: Is Java pass by reference? I have a question about passing by
Possible Duplicate: Is Java pass by reference? when I used some java class like
Possible Duplicate: How to reference another property in java.util.Properties? look at my file.properties: key1=
Possible Duplicate: Reference - What does this symbol mean in PHP? Is there any
Possible Duplicate: Is Java pass-by-reference? Java pass by reference For the following Java program,
Possible Duplicate: Is Java pass-by-reference? I found an unusual Java method today: private void
Possible Duplicate: Does a const reference class member prolong the life of a temporary?
Possible Duplicate: C# - Reference type still needs pass by ref? class OutReturnExample {
Possible Duplicate: C#: How to reference generic classes and methods in xml documentation I
Possible Duplicate: Call-time pass-by-reference has been deprecated While it may be documented somewhere on

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.