문제

I have a series of API calls that are returning J# data types. I have been able to convert most of the data types (Integer, Boolean, Double, Float, etc) just fine.

What I need to do now is convert a java.Util.Collection to a VB .NET collection (ArrayList?)

Here is my attempt:

Public Function MakeDotNETCollection(ByVal javaCol As java.util.Collection) As Collection

    Dim dotNetCol As Collection

    If Not javaCol Is Nothing Then
      dotNetCol = New Collection

      Dim it As IEnumerator = javaCol.iterator()

      For Each it In CType(javaCol, Collection)
        dotNetCol.Add(it.Current)
      Next it

    End If

    Return dotNetCol
  End Function

I keep getting a runtime error "Unable to cast object of type 'AbstractListlistIterator' to type 'System.Collections.IEnumerator. Any ideas?

도움이 되었습니까?

해결책

Not tested, but should work:

Public Function MakeDotNETCollection(ByVal javaCol As java.util.Collection) As Collection

  Dim dotNetCol As Collection

  If Not javaCol Is Nothing Then
    dotNetCol = New Collection

    Dim it As java.util.Iterator = javaCol.iterator()

    While it.HasNext()
      dotNetCol.Add(it.next())
    End While

  End If

  Return dotNetCol

End Function
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top