From the Kotlin docs
object Obj {
const val CONST = 1
}
Should be enough for accessing from Java as Obj.CONST
But with similar it got error.
object StringUtils {
const val UNESCAPE_HTML4 = "... ..."
......
}
In Java code
return StringUtils.UNESCAPE_HTML4;
Got error
'UNESCAPE_HTML4' has private access in com.data.utils.StringUtils
Has to use StringUtils.INSTANCE.getUNESCAPE_HTML4()
then no error.
Clicking on that UNESCAPE_HTML4
does opens the compiled code correctly though.
The only difference is this object StringUtils is from a libray dependency which has been added to the project's build.gradle
Anyone also seeing this type error?
Here is a test function in the Java side, which tries to access those function, property from the dependent library.
public class DataWrapper {
... ...
public void test_strUtil() {
/*
* For example, the string "<Français>"
* will become "<Franais>"
*/
String s = StringUtils.unescapeHtml4("&lt;Fran&ccedil;ais&gt;");
int s2 = Constants.CONTROLLER_FANTASY_SPORTS_STREAM;
String[][] arr = EntityArrays.BASIC_UNESCAPE();
Log.i("+++", "+++ test_strUtil(), after DataPlay.init(), unescapeHtml4:"+s+", empty:"
+StringUtils.EMPTY+" --- s2:"+s2);
for (int i=0; i<arr.length; i++) {
String[] arrRow = arr[i];
for (int j=0; j< arrRow.length; j++) {
Log.w("+++", "+++ arrRow["+i+"]["+j+"]:"+arrRow[j]);
}
}
}
The IDE shows red on them and says "non static method...",
Or "has private access..."
But when clicking on the complained function or property, it does opens the correct compiled file
And
And when it runs, the print out shows the function called correctly.
com.test.debug I/+++: +++ test_strUtil(), after DataPlay.init(),
unescapeHtml4:<Français>, empty: --- s2:3
com.test.debug W/+++: +++ arrRow[0][0]:"
+++ arrRow[0][1]:"
+++ arrRow[1][0]:&
+++ arrRow[1][1]:&
+++ arrRow[2][0]:<
+++ arrRow[2][1]:<
+++ arrRow[3][0]:>
+++ arrRow[3][1]:>
And more weird is from same library the other function and property exposed through different object class's const or @JvmStatic they don't get complain by the IDE.