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

  • Home
  • SEARCH
  • 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 7916461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:49:02+00:00 2026-06-03T14:49:02+00:00

Is it possible to have a list and use it as an argument for

  • 0

Is it possible to have a list and use it as an argument for a closure signature that instead several variables? The reason is that I have to call a closure from java code, and the java code won’t know what variables the groovy closure needs.

This is better served with an example.

Say I have a ‘closure repository’, where each closure might have different signatures. EG:

closures = [
    closureA: { int a, String b ->
        a.times {
            System.err.println(b);
        }
    },
    closureB: { int a, int b, String c ->
        (a+b).times {
            System.err.println(c);
        }
    }
]

Then I’ve got a method that I’m exposing to my java code to call these closures:

def tryClosureExpansion(String whichClosure, Object ... args) {
    def c = closures[whichClosure]
    c.call(args)     // DOESNT COMPILE !
}

And it Java I’d call this method like this:

// these calls will happen from Java, not from Groovy
tryClosureExpansion("closureA", 1, "Hello");
tryClosureExpansion("closureB", 1, 5, "Hello more");

See above on the line that doesn’t compile. I feel like groovy is ‘groovy’ enough to handle something like this. Any alternative that might fly?

  • 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-03T14:49:05+00:00Added an answer on June 3, 2026 at 2:49 pm

    Does:

    c.call( *args )
    

    Work? Not at a computer atm to test it

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

Sidebar

Related Questions

Is it possible to use Except() for two List's that have two different classes
Possible Duplicate: Java - Regex problem I have list of URLs of types: http://www.example.com/pk/etc
I have an input field that uses Autocomplete to show a list of possible
It's possible to use TRACE macro as printf like function (variable argument list) .
Possible Duplicate: <: cannot begin a template argument list Did you know that int
Possible Duplicate: Remove duplicates from a List<T> in C# i have a List like
Is it possible to have a list be evaluated lazily in Python? For example
Possible Duplicate: Concatenating a C# List of byte[] I have a list of byte[]
Possible Duplicate: Natural Sort Order in C# I have a list with a lot
how can i make it possible say i have a unordered list of 17

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.