title: Volley: Kotlin Class call from JavaCode
body: <p>I'd like to make simple Volley POST Requests due Java and Kotlin. I'm using both languages in my App so I tried do to my best to use both languages.
  I came over <a href="https://medium.com/@nishinraj/simplifying-volley-requests-kotlin-development-1bb87c3fb6f8" rel="nofollow noreferrer">this</a> tutorial with the following VolleyClass in Kotlin:</p>
  
  <p>class WolfRequest(val url: String,
                    val result: (JSONObject) -> Unit,
                    val error: (String) -> Unit) {</p>
  
  <pre><code>fun POST(vararg params: Pair&lt;String, Any&gt;) {
      // HashMap to pass arguments to Volley
      val hashMap = HashMap&lt;String, String&gt;()
      params.forEach {
          // Convert all Any type to String and add to HashMap
          hashMap[it.first] = it.second.toString()
      }
      // Make the Http Request
      makeRequest(Request.Method.POST, hashMap)
  }
  
  private fun makeRequest(method: Int, params: HashMap&lt;String, String&gt;) {
      // Creating a StringRequest
      val req = object : StringRequest(method, url, { res -&gt;
  
          // Creating JSON object from the response string
          // and passing it to result: (JSONObject) -&gt; Unit function
          result(JSONObject(res.toString().trim()))
      }, { volleyError -&gt;
  
          // Getting error message and passing it
          // to val error: (String) -&gt; Unit function
          error(volleyError.message!!)
      }) {
          // Overriding getParams() to pass our parameters
          override fun getParams(): MutableMap&lt;String, String&gt; {
              return params
          }
      }
  
      // Adding request to the queue
      volley.add(req)
  }
  
  // For using Volley RequestQueue as a singleton
  // call WolfRequest.init(applicationContext) in
  // app's Application class
  companion object {
      var context: Context? = null
      val volley: RequestQueue by lazy {
          Volley.newRequestQueue(context
                  ?: throw NullPointerException(" Initialize WolfRequest in application class"))
      }
  
      fun init(context: Context) {
          this.context = context
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I'm trying to access this Code from a Java.Class to make a POST Reuqest:</p>
  
  <pre><code>    WolfRequest.Companion.init(getApplicationContext());
      HashMap &lt;String, String&gt; params = new HashMap &lt;&gt; ();
      params.put("id", "123");
  
      new WolfRequest(config.PING_EVENTS,*new WolfRequest()*
      {
  
          public void response(JSONObject response) {
              Log.e("Ping","PING");
          }
  
          public void error(String error) {
              Log.e("Ping",error);
          }
      }).POST(params);
  </code></pre>
  
  <p>It gives me an error here (<em>new WolfRequest()</em>) saying: Cannot inherit from final "...wolfrequest.kt"</p>
  
  <p>I really don't get the error, what's the problem here?</p>
  
  <p>Thank you</p>