Fix test by using downcasts
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5592 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
7d6858ce0f
commit
c81661122e
1 changed files with 10 additions and 17 deletions
|
|
@ -18,31 +18,24 @@ public class virtual_poly_runme {
|
||||||
NDouble d = new NDouble(3.5);
|
NDouble d = new NDouble(3.5);
|
||||||
NInt i = new NInt(2);
|
NInt i = new NInt(2);
|
||||||
|
|
||||||
NInt j = virtual_poly.incr(i);
|
|
||||||
//
|
//
|
||||||
// These two natural 'copy' forms fail, only java and csharp
|
// These two natural 'copy' forms fail because no covariant (polymorphic) return types
|
||||||
// because no polymorphic return types are supported.
|
// are supported in Java.
|
||||||
// But we can live with this restriction, more or less.
|
|
||||||
//
|
//
|
||||||
// NDouble dc = d.copy();
|
// NDouble dc = d.copy();
|
||||||
// NInt ic = i.copy();
|
// NInt ic = i.copy();
|
||||||
|
|
||||||
//
|
//
|
||||||
// These two 'copy' forms work, but we end with plain NNumbers
|
// Unlike C++, we have to downcast instead.
|
||||||
//
|
//
|
||||||
NNumber dc = d.copy();
|
NDouble dc = (NDouble)d.copy();
|
||||||
NNumber ic = i.copy();
|
NInt ic = (NInt)i.copy();
|
||||||
|
|
||||||
|
NDouble ddc = (NDouble)NDouble.narrow(dc);
|
||||||
|
NInt dic = (NInt)NInt.narrow(ic);
|
||||||
|
|
||||||
//
|
virtual_poly.incr(ic);
|
||||||
// The real problem is that there is no way to recover the
|
if ( (i.get() + 1) != ic.get() )
|
||||||
// original NInt or NDouble objects, even when you try to use the
|
throw new RuntimeException("incr test failed");
|
||||||
// plain and natural C++ dynamic_cast operation, or the user
|
|
||||||
// downcasting mechanism:
|
|
||||||
//
|
|
||||||
|
|
||||||
// don't work
|
|
||||||
NDouble ddc = NDouble.narrow(dc);
|
|
||||||
NInt dic = NInt.narrow(ic);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue