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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:19:05+00:00 2026-05-13T21:19:05+00:00

This question is hard to phrase, so I’m going to have to use some

  • 0

This question is hard to phrase, so I’m going to have to use some code samples. Basically, I have an (overloaded) method that takes 3 parameters, the last of which I overloaded. As in, sometimes the last parameter is a String, sometimes it’s a double, etc. I want to call this method using a ternary conditional expression as the last parameter, so that depending on a certain value, it will pass either a double or a String. Here’s an example…

Overloaded method headers:

writeToCell(int rowIndex, int colIndex, double value)

writeToCell(int rowIndex, int colIndex, String value)

What I’m trying to do:

writeToCell(2, 4, myValue != null ? someDouble : someString);

This, however, causes a compilation error:

The method writeToCell(int, int, double) in the type MyType is not applicable 
for the arguments (int, int, Object&Comparable<?>&Serializable)

It seems that Java isn’t “smart enough” (or just doesn’t have the functionality built in on purpose) to realize that either option has a method that supports it. My question is – is there any way to do this? I know I can sort of simulate it by passing in the double as a String (e.g. writeToCell(2, 4, myValue != null ? someDouble.toString() : someString);), but the method needs to receive it as a double data type.

Logic tells me that there’s no way to force Java to accept this statement… But it’s worth a try, as it will result in a lot clearer code for me. Anyone know of a way to do this…?

  • 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-13T21:19:05+00:00Added an answer on May 13, 2026 at 9:19 pm

    Thanks everyone for all your suggestions and explanations.

    A coworker of mine took a look at my code and suggested a solution that I implemented. I inserted the following code into the beginning of my double method:

    if(value == null){
       writeToCell(rowIndex, colIndex, someString)
    }
    else{
       ...method body... 
    }
    

    I know that this implementation might not always be the best idea, but since I almost always need to check for null when passing a double value to this method, it makes the most sense in this situation. This way I don’t have to repeat the check code (if / ternary statement) each time, and my method calls are much cleaner.

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

Sidebar

Related Questions

I always had this question that where (RAM / HARD DISK / some other
Alright, hard to phrase an exact title for this question, but here goes... I
This is a very hard to explain question and I hope my code extract
This might be a simple question for some people since it was quite hard
As this question is hard to describe, that's the best title i could come
Hi this question or problem i have its very hard i have search and
It's hard to summarize this question into one sentence. I have two tables -
It was hard to phrase this question. I'll assume most of you are aware
This question is hard to explain so please bear with me. I have a
I am sure that this question is already answered, but I find it hard

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.