How can we call such a kotlin method in a class?

fun Locale?.languageName(): String = this?.getDisplayLanguage(this)?.capitalize() ?: "" 
  • And where did you announce it? - Eugene Krivenja
  • @EugeneKrivenja announced in class LocaleTools - Inkognito
  • Ok, change the question on the fly, then you need from Java, now from Kotlin. - Eugene Krivenja

2 answers 2

Try this:

 var text = Locale.getDefault().languageName() 

    If I declare it in the com.example.Extentions package, the compiler will create an ExtentionsKt class there with this method as static.

    Accordingly, from Java the call will be like this:

     String languageName = com.example.Extensions.ExtensionsKt.languageName(Locale.CANADA); 
    • Already even converted a class into a cotlin and try to call something like this `val languageName = com.sai.android.utils.languageName (locale)` but languageName is still unresolved - Inkognito
    • And who said that he would be called like that in Kotlin? :) - Eugene Krivenja
    • It seems like `var text text = getLocale (). LanguageName ()` but getLocale () is still unresolved reference ( - Inkognito
    • If you announce correctly, everything will resolve. Understand the scope. - Eugene Krivenja