简体   繁体   中英

how to read parameters from console to method in groovy?

I am new to groovy.I am reading values for 2 variables from console with below lines of code.

System.in.withReader {   
  println "Version: "  
  version = it.readLine()  
  println "Doc Type:"  
  Doc=it.readLine()  
  call getBillID(version,Doc)
}

getBillid method is as below,

def getBillID(int version,int doc)
{  
  allNodes.BillID.each {
    theregularExpression=/\d+_\d+_\d+_\d_\d+_\d+_\d_${version}_${Doc}_\d+_\d+/
    if(it != "" && it =~ theregularExpression) {
      println "******" + it
    }
  }
}

now i want to use those variable values in my getBILLID method but i am getting error as

No signature of method: ReadXML.getBillID() is applicable for argument types: (java.lang.String, java.lang.String) values: [9, ]

where i went wrong.can any one tell me plz..

In addition to @Kalarani's answer, you could also do this:

System.in.withReader {
  print "Version: "
  int version = it.readLine() as int
  print "Doc Type: "
  int doc = it.readLine() as int
  getBillID( version, doc )
}

As an aside; I would be careful with your capitalisation and variable names, ie: you have a variable called Doc with a capital letter. This is not the standard naming scheme, and you are best using all lowercase for variable names. You can see where it has got confused in the getBillID method. The parameter is called doc (all lowercase), but in the regular expression you reference ${Doc} (uppercase again).

This sort of thing is going to end up causing you a world of pain and bugs that might take you longer to find

Where is the getBillId() method defined? and what is the signature of the method? It would help understanding your problem if you could post that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM