[fpc-devel] FPC-JVM: Problem with String => CharSequence

Sven Barth pascaldragon at googlemail.com
Sun Aug 28 22:02:26 CEST 2011

On 28.08.2011 21:32, Jonas Maebe wrote:
> On 27 Aug 2011, at 12:00, Sven Barth wrote:
>> Now that the cycle problem was solved  (I don't know whether it works, because I'm still trying to get a test working ^^), I've encountered the next problem. The android.widget.TextView class has a method setText that takes a CharSequence which is implemented by java.lang.String. As I've read in the wiki UnicodeString is mapped to that type. But the following code pieces don't compile (tv is the TextView of type AWTextView):
> The fact that something is implemented by something else does not mean that the semantics are identical. E.g. a "var s: set of TSomeEnum" is implemented via java.util.EnumSet, but that does not mean that you can pass such a set to any method expecting a java.util.EnumSet. Similarly, you cannot use "include()" with a java.lang.EnumSet class instance. One is a Pascal set type, the other is a Java class type and both have their own behaviour. It is however possible to typecast one to the other via JLEnumSet(@enumsetvar) and PEnumSetType(enumsetinstance)^.
> Now, because strings are so common there's an exception in that unicodestrings will be implicitly typecasted to java.lang.String and vice versa (and in the svn version of the compiler, ansistrings and shortstrings will also be automatically converted to and from java.lang.String without typecasts). Automatic typecasting from unicodestring to java.lang.CharSequence could be added, but then it should also be added to java.lang.Object and then you very can get "cannot choose which overloaded method to call" situations, so I'm not sure whether this is a good idea.

Ok, thank you for the explanation of the behavior.

Would adding an operator overload for implicit cast solve the problem? 
I'm not talking about adding it to System or JDK15, but maybe a seperate 


More information about the fpc-devel mailing list