using [java]fanx.interop::Interop
using [java]java.util::ArrayList
class TestList : Test{
Void test(){
arrList := ArrayList()
arrList.add(ArrayList())
arrList.add(ArrayList())
arrList.add(ArrayList())
// case 1
ArrayList[] inlineMe := Interop.toFan(arrList.iterator)
row := inlineMe.map|tr|{tr.toString}
// case 2
row2 := Interop.toFan(arrList.iterator).map|ArrayList tr|{tr.toString}
// failed
verifyEq(row,row2)
}
}
Output:
TEST FAILED
sys::TestErr: Test failed: sys::Obj?[[], [], []] != sys::Obj?[null, null, null]
vkuzkokovSat 28 Aug 2010
It's not inlining. It's type inference. You explicitly say that inlineMe is ArrayList[], while toFan returns Obj?[]. If you will delete explicit ArrayList[] you'll get compilation error on the next line. It's because tr type will be resolved as Obj? and therefore won't have toString.
The idea of the above is that case 1 and case 2 are not supposed to do the same.
Here, case 1 gives us what is expected. [] is the value of toString for empty list in java. You can use non-empty list for clarification. when you write:
Akcelisto Sat 28 Aug 2010
using [java]fanx.interop::Interop using [java]java.util::ArrayList class TestList : Test{ Void test(){ arrList := ArrayList() arrList.add(ArrayList()) arrList.add(ArrayList()) arrList.add(ArrayList()) // case 1 ArrayList[] inlineMe := Interop.toFan(arrList.iterator) row := inlineMe.map|tr|{tr.toString} // case 2 row2 := Interop.toFan(arrList.iterator).map|ArrayList tr|{tr.toString} // failed verifyEq(row,row2) } }Output:
vkuzkokov Sat 28 Aug 2010
It's not inlining. It's type inference. You explicitly say that
inlineMeisArrayList[], whiletoFanreturnsObj?[]. If you will delete explicitArrayList[]you'll get compilation error on the next line. It's becausetrtype will be resolved asObj?and therefore won't havetoString.The idea of the above is that case 1 and case 2 are not supposed to do the same.
Here, case 1 gives us what is expected.
[]is the value of toString for empty list in java. You can use non-empty list for clarification. when you write:row := inlineMe.map|tr|{tr.toString}it's understood as:
row := inlineMe.map|ArrayList tr->Obj?| { tr.toString }Note that it's different from
inlineMe.map|ArrayList tr| { tr.toString }because latter returns
Void. Thusrow2is an array ofVoids which are interpreted as nulls (we can't haveVoid[]indeed).Akcelisto Sat 28 Aug 2010
Thanks to vkuzkokov. I understood: case 1 and case 2 is not equivalent.
using [java]fanx.interop::Interop using [java]java.util::ArrayList class TestList : Test{ Void test(){ arrList := ArrayList() arrList.add(ArrayList()) arrList.add(ArrayList()) arrList.add(ArrayList()) // case 1 ArrayList[] inlineMe := Interop.toFan(arrList.iterator) row := inlineMe.map|tr|{tr.toString} // case 2 row2 := Interop.toFan(arrList.iterator).map|ArrayList tr->Obj?|{tr.toString} // passed verifyEq(row,row2) } }Now test passed.