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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:02:19+00:00 2026-06-13T20:02:19+00:00

Sorry for the vague title. I have this piece of code which compiles on

  • 0

Sorry for the vague title. I have this piece of code which compiles on Eclipse Juno (4.2) but not javac (1.7.0_09):

package test;

public final class Test {
    public static class N<T extends N<T>> {}

    public static class R<T extends N<T>> {
        public T o;
    }

    public <T extends N<T>> void p(final T n) {}

    public void v(final R<?> r) {
        p(r.o);       // <-- javac fails on this line
    }
}

The error is:

Test.java:13: error: method p in class Test cannot be applied to given types;
        p(r.o);
        ^
  required: T
  found: N<CAP#1>
  reason: inferred type does not conform to declared bound(s)
    inferred: N<CAP#1>
    bound(s): N<N<CAP#1>>
  where T is a type-variable:
    T extends N<T> declared in method <T>p(T)
  where CAP#1 is a fresh type-variable:
    CAP#1 extends N<CAP#1> from capture of ?
1 error

So the questions are:

  1. Is this a javac bug or Eclipse bug?

  2. Is there any way to make this compile on javac, without changing the signature of the v method (i.e. keep the wildcard)?

    I know changing it to <T extends N<T>> void v(final R<T> r) does make it compile, but I would like to know if there’s way to avoid this first. Also, the method p cannot be changed to <T extends N<?>> void p(final T n) because the content have types which requires the exact constraint T extends N<T>.

  • 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-13T20:02:21+00:00Added an answer on June 13, 2026 at 8:02 pm

    Wildcards are limited in that they break recursive expressions like T extends X<T> that type parameters allow. We know what you’re trying to do is safe based on the following:

    1. r.o is of type T (declared by R), which is or extends N<T>.
    2. The method p takes an argument of type T (declared by p), which also is or extends N<T>.
    3. So even though r is typed as R<?>, a call p(r.o) should theoretically be legal.

    This is possibly the reasoning of the eclipse compiler (known to make correct allowances for certain nuances of generics where javac doesn’t).

    Assuming you want to compile with javac and can’t change the signature of v like you mentioned, the best you can do is resort to using a raw type, which “opts out” of generic type checking:

    public void v(final R<?> r) {
        //necessary to placate javac - this is okay because [insert above reasoning]
        @SuppressWarnings("rawtypes")
        N nRaw = r.o;
        p(nRaw);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for the vague title, but not quite sure how to summarize this one.
Sorry for the vague title, but I wasn't sure how to summarize this in
Sorry for the vague title, but this is kind of hard to put into
Sorry for the bad title, but I have no idea how to put this
Sorry about the vague title but I have a servlet with the following mapping
Sorry for the vague title, but I've been trying to nail this for a
Sorry about the vague question title, but I have these typedefs here: typedef std::list<AnimationKeyframe>
Sorry for how vague the title is, but I'm not completely sure how to
Sorry about the vague title, but I really don't know how to describe this
Sorry i could not find a proper title to this question. I have generated

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.