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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:10:36+00:00 2026-05-15T05:10:36+00:00

The following code compiles perfectly with Eclipse, but fails to compile with javac: public

  • 0

The following code compiles perfectly with Eclipse, but fails to compile with javac:

public class HowBizarre {
      public static <P extends Number, T extends P> void doIt(P value) {
      }

      public static void main(String[] args) {
            doIt(null);
      }
}

I simplified the code, so T is not used at all now. Still, I don’t see a reason for the error.
For some reason javac decides that T stands for Object, and then complains that Object does not conform to the bounds of T (which is true):

HowBizarre.java:6: incompatible types; inferred type argument(s)
java.lang.Number,java.lang.Object do not conform to bounds of type
variable (s) P,T

found : <P,T>void

required: void

       doIt(null);
           ^

Note that if I replace the null parameter with a non-null value, it compiles fine.

Which of the compilers behaves correctly and why? Is this a bug of one of them?

  • 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-15T05:10:37+00:00Added an answer on May 15, 2026 at 5:10 am

    The problem is due to a JLS specification that mandates that otherwise uninferrable type arguments must be inferred as Object, even if it doesn’t satisfy the bounds (and would consequently trigger a compilation error).

    The following is an excerpt from the "bug" report (which has been further annotated for clarity):

    "Bug" ID 6299211 – method type variable: inference broken for null

    This program does not compile:

    public class Try {
    
        void m() {
            java.util.Collections.max(null);
        }
    }
    

    State: CLOSED, NOT A DEFECT.

    Evaluation: THIS IS NOT A BUG. The inference algorithm cannot gather any information from the argument (null) and the method is not called in a place where there are any expectations on the returned value. In such cases the compiler must infer java.lang.Object for the type variable.


    JLS 15.12.2.8 Inferring Unresolved Type Arguments

    Any remaining type variables that have not yet been inferred are then inferred to have type Object


    However, Object is not a subtype of Comparable<? super Object> and thus not within the bounds of the type variable in the declaration of Collections.max:

    <T extends Object & Comparable<? super T>> T max(Collection<? extends T>)


    Further explorations

    Using explicit type parameters "fixes" the problem:

    HowBizarre.<Number,Integer>doIt(null); // compiles fine in javac
    

    To show that this has less to do with a null argument and more to do with the absolute lack of information for type inferrence, you can try e.g. either of the following declarations:

    <T,U extends Comparable<T>> void doIt()
    
    <T extends Number,U extends T> void doIt()
    

    In either case, an invocation doIt(); doesn’t compile in javac, as it must infer U to be Object as per 15.12.2.8, even if doing so would trigger a compilation error.


    Note on Eclipse

    While none of the snippets above compile in some version of javac, they all do in some version of Eclipse. This would suggest a bug on Eclipse’s part. It’s been known that there are disagreements between the different compilers.

    Related questions

    • Generics compiles and runs in Eclipse, but doesn’t compile in javac
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code compiles and runs perfectly, #include <iostream> class sam { public: void
The following code compiles in Visual C++ and gcc, but fails with Code Warrior
I'm trying to compile following code in VC++ 2010: class Base { public: std::wstring
the following code compiles with Visual Studio 2008 but not with g++ on Mac
The following source code compiles correctly with Visual Studio 2010: namespace NS { class
I have the following code, which compiles but doesn't bring back any data. Here
First of all, Beginner here. I'm using this code. class MDArrays { public static
Let's see the following simplest code snippet in Java. final public class Parsing {
The following code is crashing my application on startup. It compiles just fine but
The following code compiles perfectly: // MyFile.h #ifndef MYFILE_H_INCLUDED #define MYFILE_H_INCLUDED template <typename Datatype>

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.