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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:28:54+00:00 2026-05-22T15:28:54+00:00

The overloaded functions compute1() , compute2() , and compute5() cause compilation errors if you

  • 0

The overloaded functions compute1(), compute2(), and compute5() cause compilation errors if you try to use them below:

package com.example.test.reflect;

class JLS15Test2
{
    int compute1(Object o1, Integer i, Integer j)         { return 1; }
    int compute1(String s1, Integer i, int j)             { return 2; }

    int compute2(Object o1, Integer i, int j)             { return 3; }
    int compute2(String s1, Integer i, Integer j)         { return 4; }

    int compute3(Object o1, Integer i, int j)             { return 5; }
    int compute3(String s1, Integer i, int j)             { return 6; }

    int compute4(Object o1, Integer i, Integer j)         { return 7; }
    int compute4(String s1, Integer i, Integer j)         { return 8; }

    int compute5(Object o1, Integer i, Object j)          { return 9; }
    int compute5(String s1, Integer i, int j)             { return 10; }


    public static void main(String[] args) 
    {
        JLS15Test2 y = new JLS15Test2();

        // won't compile:
        // The method compute1(Object, Integer, Integer) is ambiguous 
        // for the type JLS15Test2
        // System.out.println(y.compute1("hi", 1, 1));

        // Neither will this (same reason)
        // System.out.println(y.compute2("hi", 1, 1));
        System.out.println(y.compute3("hi", 1, 1));
        System.out.println(y.compute4("hi", 1, 1));

        // neither will this (same reason)
        // System.out.println(y.compute5("hi", 1, 1));
    }
}

After reading the JLS section 15.12, I think I understand… in phase 2 (boxing/unboxing allowed, no varargs) of matching overloaded methods, when determining the “most specific method”, the JLS says (in effect) that the most specific method is the one whose formal parameters are subtypes of other applicable methods, and primitives and Objects (e.g. int and Integer) are never subtypes of each other. So Integer is a subtype of Integer, and int is a subtype of int, but Integer and int are incompatible w/r/t subtype comparisons, so neither of the compute1()/compute2() pairs have a most specific method.

(Whereas in compute3() and compute4() the method with the String argument is more specific than the method with the Object argument, so the program prints 6 and 8.)

Is my reasoning correct?

  • 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-22T15:28:55+00:00Added an answer on May 22, 2026 at 3:28 pm

    Yes, your reasoning is correct.

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

Sidebar

Related Questions

I have a bunch of overloaded functions that operate on certain data types such
I'm having a minor issue dealing with pointers to overloaded member functions in C++.
Since curried functions cannot be overloaded and modules cannot have members, does this mean
I have a lot of functions which are currently overloaded to operate on int
Ok, I'm using virtual functions, overloaded functions, and multiple inheritance. Of course this doesn't
Im writing custom docs for some java methods, and some of them are overloaded
How do I view the compiler-generated mangled names for overloaded functions in C++? I'm
I have 2 overloaded C# functions like this: private void _Insert(Hashtable hash, string tablename,
Possible Duplicate: overloaded functions are hidden in derived class I have Class A and
I need help with creating Operator-Overloaded functions please. I tried 2 but I am

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.