java.lang.Double incompatibility (with solution)

0 views
Skip to first unread message

Stefan Monov

unread,
Oct 10, 2010, 6:55:41 AM10/10/10
to qt4d...@googlegroups.com
Hi. For the n-th time I've noticed a leaky abstraction in IKVM ;)
Thought I'd share the fix with with you.

This code fails with IllegalArgumentException:

var pattern = new java.util.ArrayList();
pattern.add(1.0);
pattern.add(1.0);
new QPen().setDashPattern(list);

The fix is:

var pattern = new java.util.ArrayList();
pattern.add(new java.lang.Double(1));
pattern.add(new java.lang.Double(1));
new QPen().setDashPattern(list);

The root reasons for the problem are:
- java generics type erasure means that jambi's java.util.List<double>
is seen as java.util.List from our side (from qt4dotnet)
- Therefore we can push anything onto a list, and pass it to
setDashPattern with no static typechecking
- When we push a 1.0 onto the list, it gets boxed, but does *not* get
boxed into a java.lang.Double object - it gets boxed into a
.NETSystem.Double object
- jambi of course barfs on that System.Double since it expects a
java.lang.Double
- we workaround it by doing the java-style boxing by hand.

Reply all
Reply to author
Forward
0 new messages