Alexander Stolte Expert Licensed User Longtime User Dec 4, 2019 #1 Hey, i'm working with Visual Studio every day and there is a Feature to Initialize all with the keyword "new" for example: Dim str as new string Dim mytype as new nicetype You could initialize lists for example in the Process_Globals already at the declaration. Would that be possible someday?
Hey, i'm working with Visual Studio every day and there is a Feature to Initialize all with the keyword "new" for example: Dim str as new string Dim mytype as new nicetype You could initialize lists for example in the Process_Globals already at the declaration. Would that be possible someday?
Erel B4X founder Staff member Licensed User Longtime User Dec 4, 2019 #2 Code: Copy Dim str As String = "abc" Dim MyList As List = Array(1, 2, 3, 4) Dim MyMap As Map = CreateMap("key1": "value1") About types, see the latest version of B4J: https://www.b4x.com/android/forum/threads/b4j-v8-00-has-been-released.111727/#content There is a new 'generate CreateType' feature. With this feature you can write: Code: Copy Dim MyType As NiceType = CreateNiceType(...)
Code: Copy Dim str As String = "abc" Dim MyList As List = Array(1, 2, 3, 4) Dim MyMap As Map = CreateMap("key1": "value1") About types, see the latest version of B4J: https://www.b4x.com/android/forum/threads/b4j-v8-00-has-been-released.111727/#content There is a new 'generate CreateType' feature. With this feature you can write: Code: Copy Dim MyType As NiceType = CreateNiceType(...)
LucaMs Expert Licensed User Longtime User Dec 4, 2019 #3 Erel said: Dim MyList As List = Array(1, 2, 3, 4) Click to expand... This is "dangerous", because after this kind of initialization, the List loses its characteristics (it becomes practically an array). I will never initialize it that way
Erel said: Dim MyList As List = Array(1, 2, 3, 4) Click to expand... This is "dangerous", because after this kind of initialization, the List loses its characteristics (it becomes practically an array). I will never initialize it that way
Erel B4X founder Staff member Licensed User Longtime User Dec 4, 2019 #4 Not really dangerous. It depends on your requirements. If you want to create a mutable list then write it like this: Code: Copy Dim list As List list.Initialize list.AddAll(Array(1, 2, 3)) Or: Code: Copy Sub CreateMutableList(Items As List) As List Dim list As List list.Initialize list.AddAll(Items) Return list End Sub Dim list As List = CreateMutableList(Array(1, 2, 3)) list.Add(4)
Not really dangerous. It depends on your requirements. If you want to create a mutable list then write it like this: Code: Copy Dim list As List list.Initialize list.AddAll(Array(1, 2, 3)) Or: Code: Copy Sub CreateMutableList(Items As List) As List Dim list As List list.Initialize list.AddAll(Items) Return list End Sub Dim list As List = CreateMutableList(Array(1, 2, 3)) list.Add(4)