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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:18:57+00:00 2026-06-12T20:18:57+00:00

I am reading the book Core Java by Hortsmann and Cornell (Vol.1). In the

  • 0

I am reading the book “Core Java” by Hortsmann and Cornell (Vol.1).
In the Generics chapter, they suggest an input that is purposely wrong, in order to have a look at what the compiler says. My problem is: not only the compiler doesn’t give me the same error, but it will keep on giving me errors also when I correct the input as stated in the book. Here’s the deal:

public class PairTest1 {
    public static void main(String[] args) {
        double middle = ArrayAlg.getMiddle(3.14, 1729, 0);
    }
}

class ArrayAlg {
    public static <T> T getMiddle(T[] a) {
        return a[a.length / 2];
    }
}

The book says I should get the error:

found: java.lang.Number&java.lang.Comparable>, required: double.

Instead, Eclipse won’t let me run the program, saying

The method getMiddle(T[]) in the type ArrayAlg is not applicable for
the arguments (double, int, int)

The book then says

the remedy is to write all parameters as double values.

I therefore changed 1729 to 1729.1 and 0 to 0.1. Now Eclipse says:

The method getMiddle(T[]) in the type ArrayAlg is not applicable for
the arguments (double, double, double)

Mmmhh… I didn’t get what is going on. Suggestions?

Thank you & regards

EDIT: I tried to create the array double[] doubles = { 3.14, 1729.1, 0.1 }; and to give it as parameter, but now I get the error The method getMiddle(T[]) in the type ArrayAlg is not applicable for the arguments (double[])

  • 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-12T20:18:58+00:00Added an answer on June 12, 2026 at 8:18 pm

    You should change your call to

    double middle = ArrayAlg.getMiddle(new Double[]{ 3.14, 1729.0, 0.0 });
    

    If you want to pass them the way you are doing, then you should change the declaration to

    public static <T> T getMiddle(T... a)
    {
        return a[a.length / 2];
    }
    

    using the var-arg syntax of Java. Then you can call the method as

    double middle = ArrayAlg.getMiddle(3.14, 1729.0, 0.0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was reading a book which says that a processor with single core and
Reading the book VS 2010 by John Sharp, it says that generics allows to
Reading a book on Entity Framework and they say that LINQ is only available
I am reading some book and I have encountered a piece of code that
Reading a book about C# I noticed that sometimes is mentioned value type and
I'm reading the book Algorithms and they mentioned a data type Item . However,
I have been reading the book of Windows via C/C++. In chapter 8, page
I mentioned in one of my earlier questions that I'm reading book C++ Coding
While reading a book called Let us C I read that a function showbit()
I've been reading the book TCP/IP Sockets in Java, 2nd Edition. I was hoping

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.