I cannot pass interface to webview in kotlin

Hey Devs, I am noob to kotlin and got stuck at some point.

In Java we do this

webView.setWebChromeClient(new WebChromeClient());

I am able to achieve this line in Kotlin like this

webview.webChromeClient = WebChromeClient()

=================================================

webView.setWebViewClient(new WebViewClient() {
		
		@Override public void onPageStarted(WebView view, String url, Bitmap favicon) {
			super.onPageStarted(view, url, favicon);
			// some code

		}
		@Override public void onPageFinished(WebView view, String url) {
			super.onPageFinished(view, url);
			// some code
		}
		
		@Override public void onReceivedSslError(WebView view,
				SslErrorHandler handler, SslError error) {
			//  some code
		}
	});

But this interface passing to Java I am unable to pass it in Kotlin

Please help me if one can do.
Thanks in Advance

Dear noob, please read the documentation before asking questions.

Anonymous class creation in kotlin is done via object keyword:

webview.webChromeClient = object: WebChromeClient(){
  override fun onPageStarted(...){...}
  ...
}
1 Like