With java's compact strings feature, is there a public api to get the actual encoding or memory usage of a string? I could call either package private method coder or private method isLatin1 and adjust the calculation, but both will result in an Illegal reflective access warning.
Method isLatin1 = String.class.getDeclaredMethod("isLatin1");
isLatin1.setAccessible(true);
System.out.println((boolean)isLatin1.invoke("Jörn"));
System.out.println((boolean)isLatin1.invoke("foobar"));
System.out.println((boolean)isLatin1.invoke("\u03b1"));