B4J Question Find what type of object is in a list

Tim Chapman

Active Member
Licensed User
Longtime User
I have created 2 new Types.
I have a list of one type and another list of the other type.

I want to make a sub where a list is passed to the sub.

I want the sub to be able to figure out which list is being used by finding out which Type the list is filled with.

Is that possible?
 

behnam_tr

Active Member
Licensed User
Longtime User
also you can use


B4X:
   Type MyType (Name As String, Items(10) As Int)
Type MyType2 (Name As String, Items(10) As Int)

    
Dim a As MyType
    a.Initialize
    a.Items(2) = 123
    
    Dim b As MyType2
    b.Initialize
    b.Name = "test"
    
    
    Dim list1 As List
    list1.Initialize
    list1.Add(a)
    list1.Add(b)
    
    Log(GetType(list1.Get(0)))
    Log(GetType(list1.Get(1)))
    Log(list1.get(0) Is MyType)
    Log(list1.get(1) Is MyType)
 
Last edited:
Upvote 1

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top