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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:33:42+00:00 2026-05-20T20:33:42+00:00

HI all, the following code does not getting executed, the code is class Invoice{

  • 0

HI all, the following code does not getting executed, the code is

class Invoice{
        List items
        Date date
}
class LineItem{
        Product product
        int count
        int total(){
                return product.dollar * count
        }
}
class Product{
        String name
        def dollar
}
def ulcDate = new Date(107,0,1)
def ulc = new Product(name:'ULC', dollar:200)
def ve = new Product(name:'Visual Editor',dollar:500)
def invoices =[new Invoice(date:ulcDate, items: [new LineItem(count:5, product:ulc),new LineItem(count:2, product:ve)]), new Invoice(date:[107,1,1],items:[new LineItem(count:4,product:ve)])]
assert [200,500,400] == invoices.items*.total()

This file name is Test.groovy and when i execute like this groovy Test i’m getting an error like this :

Caught: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.total() is applicable for argument types: () values: []
Possible solutions: tail(), getAt(groovy.lang.Range), getAt(java.util.Collection), getAt(int), getAt(java.lang.String), getAt(java.lang.String)
    at In1.run(In1.groovy:20)

Even though i have defined the total() method, it throws an error? Whats the reason for it?

  • 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-20T20:33:43+00:00Added an answer on May 20, 2026 at 8:33 pm

    Regarding the line:

    assert [200,500,400] == invoices.items*.total()
    

    invoices.items returns a List<List<LineItem>> so invoices.items*.total() fails because the outer List doesn’t have a total() method.

    If you want to get the total of each LineItem, just remove the outer List by calling flatten()

    assert [1000, 1000, 2000] == invoices.items.flatten()*.total()
    

    If you want to get the total value of each invoice, try the following

    assert [2000, 2000] == invoices.items*.sum { it.total() }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code is visual basic, .NET, ASP... all of the above? Can anybody
I have the following code to zip all the files and then save it
I have the following code: // Obtain the string names of all the elements
I noticed (and verified in the sunspot code) the following behavior class Foo <
I have a question regarding the following code: abstract class a { public static
(All of the following is to be written in Java) I have to build
The rails books and web pages I've been following have all stuck to very
The following query will display all Dewey Decimal numbers that have been duplicated in
What all would be the requirements for the following scenario: A GSM modem connected
We all know you can't do the following because of ConcurrentModificationException : for (Object

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.