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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:47:59+00:00 2026-05-16T04:47:59+00:00

I have an old untyped class pre Java1.5 and need to refactor it using

  • 0

I have an old untyped class pre Java1.5 and need to refactor it using Java Generics to get more type security in the code.

Old Code looks like this:

class Foo { 
  void setInput(Object input) {...}
}

Now this input could be some object but it may also be an array, nasty stuff. Making a generic version of it seems not to be trivial, I tried:

class Foo<E> {
  void setInput(E input) {...}
  void setInput(E[] input) {...}
}

The problem is that this is ambiguous for example for calls:

Foo f = Foo<SomeClassyClass>();
f.setInput(null);

Is there some good solution to this problem or do I need to take a completely other approach?

Thanks,
Patrick

  • 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-16T04:48:00+00:00Added an answer on May 16, 2026 at 4:48 am

    This type of ambiguity is not new to generics but can always happen with overloaded methods. You have to cast the null:

    Foo<String> f = new Foo<String>();
    
    f.setInput((String[]) null);
    f.setInput((String) null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an old skin that I need to adapt to the new MediaWiki
I have old rails application. And this application need the same gem with different
I have old.htm and new.htm on a directory, and I need to load file.php
We have old .net 1.1 project that is using a third party component. Aparently
Since Scala does not have old Java style for loops with index, // does
We have an old project written using Managed C++ syntax. I would like to
I have an old eclipse java project which is stored in SVN. I wish
1) I have old project that I need to modify. I need to add
I have old text inside a div. I want that text to fly out
I have old code that uses size_t which IIRC comes from cstring.h. On OS

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.