[Ikvm-developers] RE: Ghosts and java.lang.CharSequence
Brought to you by:
jfrijters
|
From: Jeroen F. <je...@su...> - 2003-07-31 16:11:46
|
Jonathan Pierce wrote:
> Please look at my implementation of subsequence again. I=20
> don't think you can avoid using your ghost interface
> implementation magic for interfaces. The approach I am
> suggesting allows you to keep the type information of the
> arguments, and eliminate the conditional logic in your helper
> implementation.
OK. I finally looked at your implementation. You are trading one evil
for another one ;-) You will have object identity problems and I think
the code generation will be harder than for my solution. I did actually
consider this approach when I started IKVM, but ultimately decided that
it wouldn't be the right way to go.
How would you compile this:
Object o =3D "foo";
CharSequence seq =3D (CharSequence)o;
Presumably like this:
Object o =3D "foo";
CharSequence seq;
if(o instanceof String)
seq =3D new StringWrapper((String)o);
else
seq =3D (CharSequence)o;
Now what happens when I test identity:
if(seq =3D=3D "foo")
{
// ...
}
This fails, unless seq is unwrapped again. Or are you suggestion always
wrapping strings in a StringWrapper? This has it's own set of problems:
- you lose object identity when interoperating with other .NET code
- performance loss due to extra indirection (this is significant for
strings)
- need to write own version of String.intern()
- it works for String (because it is final), but it is not a general
solution (doesn't work for making Throwable appear to implement
Serializable)
Regards,
Jeroen
|