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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:35:12+00:00 2026-05-31T16:35:12+00:00

I searched StackOverflow before posting this question but I wasn’t able to find the

  • 0

I searched StackOverflow before posting this question but I wasn’t able to find the right answer. Sorry if this is a repost. My problem is this:

I have a method that is overloaded in my java class:

class ABC{

    public boolean doSomething(String path, ArrayList<SomeObject> objList){
        // calling the method below in a loop
    }

    public boolean doSomething(String path, SomeObject obj){
       // Some code here
    }
}

I’m calling the above class from my groovy code like this:

void performDoSomething(ABC abc, String path, String[] strList){
    def list = []
    for (str in strList) {
        SomeObject sObj = new SomeObject(str)    // EDIT: sorry I missed this line before
        list.add(sObj)
    }
    if (abc) abc.doSomething(path, list)
}

The problem is that the groovy compiler is calling the abc.doSomething(String str, SomeObject obj) method instead of abc.doSomething(String str, ArrayList objList) method.

I’m using eclipse IDE with grails plugin (STS) and this is part of a bigger grails project (our company has a lot of legacy code in java).

Any ideas on how to fix this?
Thank you for your time!

EDIT: I have tried
abc.doSomething(path, list as ArrayList)
too but I’m getting the same result..

  • 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-31T16:35:13+00:00Added an answer on May 31, 2026 at 4:35 pm

    Can you reproduce this with a simple example using the classes you mention? I tried, but I got the expected behavior.

    SomeObject.java::

    public class SomeObject {
        public String what;
        public SomeObject(String what) {
            this.what = what;
        }
    }
    

    ABC.java:

    import java.util.List;
    
    public class ABC {
        public void doSomething(String path, List<SomeObject> objects) {
            System.out.println("Doing something with many objects");
            for (SomeObject obj : objects) {
                doSomething(path, obj);
            }
        }
    
        public void doSomething(String path, SomeObject obj) {
            System.out.println("Doing something with: " + obj.what);
        }
    }
    

    test.groovy:

    void performDoSomething(ABC abc, String path, String[] strList){
        def list = []
        for (str in strList) {
            SomeObject sObj = new SomeObject(str)    // EDIT: sorry I missed this line before
            list.add(sObj)
        }
        if (abc) abc.doSomething(path, list)
    }
    
    performDoSomething(new ABC(), 'some path', ['hello', 'world'] as String[])
    

    I run this doing (in the same directory as the files):

    javac *.java
    groovy test.groovy
    

    And the output I get is:

    Doing something with many objects
    Doing something with: hello
    Doing something with: world
    

    Which means that the correct overloaded method, doSomething(String, List<SomeObject>), is being called by Groovy. This is what is expected, as Groovy uses the runtime type information on the methods to decide which overloaded version to call (an example of this can be found here). I would not recommend changing the signature of doSomthing as suggested, as it will pollute the class’ interface unnecessarily; the problem is probably somewhere else.

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

Sidebar

Related Questions

I searched StackOverflow but couldn't find the answer to this question. Suppose I have
I've searched this question in Stack Overflow before posting it, but none of the
I searched stackoverflow but couldnt find a answer(sure there is one somewhere) but I
Forgive me if this is a repeat question. I've searched StackOverflow and did not
I searched for this and found Maudite's question about text editors but they were
I have searched a lot but not able to find particular solution. There are
I know this question has been asked many times, and I've searched stackoverflow and
I realize this question is very likely to have been asked before, but I've
Ok, I searched the internet and stackoverflow but I just can't seem to find
I've searched the web and I've searched the questions here on stackoverflow, but I

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.