title: Android Kotlin how to pass named function as parameter into another function to be executed when JsonObjectRequest return success?
body: <p>I have a function named doReq it will do a JsonObjectRequest and when success i need it to execute a named function i pass in with the success response return from the request. Please take a look at code below,</p>
  
  <pre><code>package mypackage1
  fun reqSuccess(resp: JSONObject) {    
  }
  </code></pre>
  
  <pre><code>package mypackage2
  fun doReq(url: String, how do i pass in reqSuccess function here?) {                
      val req: JsonObjectRequest = object : JsonObjectRequest(Request.Method.POST, url, json,
              Response.Listener { response -&gt;
                  // need to perform reqSuccess here passing in response
              },
              Response.ErrorListener { error -&gt;
              }
      )
  }
  </code></pre>
  
  <p>Additional note, doReq will be called in other packages and each package has it's own reqSuccess function. Ok below is correct now,</p>
  
  <pre><code>    package mypackage2
      fun doReq(url: String, onSuccess: (response: JSONObject) -&gt; Unit) {
          val req: JsonObjectRequest = object : JsonObjectRequest(Request.Method.POST, url, json,
                  Response.Listener { response -&gt;
                     onSuccess(response)
                  },
                  Response.ErrorListener { error -&gt;
                  }
          )
      }
  </code></pre>
  
  <pre><code>package mypackage1
  fun reqSuccess(resp: JSONObject) {    
  }
  
  doReg("someurl",::reqSuccess)
  </code></pre>