clubfan
11/05/2017, 9:37 PMnucc
11/05/2017, 9:40 PMlazy
keyword that might can help for me, but I don't know how I could use it in a data class. I want something like in C++ how we define a const
instance variable in the constructor. Here is an example what I would like to do:
data class MyClass(val property: String) { # <-- mutable
init {
this.property = property.capitalize()
}
}
instance = MyClass("test")
instance.property # Test
instance.property = "test2" # error, immutable variable
but unfortunately the compiler says Val cannot be reassigned
when I set this.property
. Do you know how I could use immutable instance variable here?jen20
11/05/2017, 10:20 PMkristofdho
11/06/2017, 2:44 AMdasz
11/06/2017, 9:26 AMkatz
11/06/2017, 1:01 PMobject : TypeOf<ArrayList<CityInfo>>() {}
class to allow gson to deserialize, so it means i need declare class exactly, any templates return type as T (not as ArrayList<CityInfo>)mike_shysh
11/06/2017, 1:57 PMfun CustomerInfo.addRandomPartToName(): CustomerInfo {
val oldItem = this.customerInfo <<<< `this` is not usable
val newItem = oldItem?.copy(name = oldItem.name + RandomStringUtils.randomAlphabetic(7))
return this.copy(customerInfo = newItem)
}
louiscad
11/06/2017, 2:08 PMobject
, enum
and other Kotlin keywords if possible in a project? I'm looking for an OS agnostic way to count them if possible as I work on macOS and Windows 10thos
11/06/2017, 2:39 PMhagabaka
11/06/2017, 5:44 PMkristofdho
11/06/2017, 6:29 PMfun <T> Deferred<Unit,T>.resolve() = resolve(Unit)
kartikpatodi
11/06/2017, 8:22 PMinline fun <reified T> membersOf() = T::class.members
fun main(s: Array<String>) {
println(membersOf<StringBuilder>().joinToString("\n"))
}
https://try.kotlinlang.org/#/UserProjects/e8imtmr1ecig3054eh01oekq8q/s05q8o8o76i5jkum3ov36o3gpckovrik
11/07/2017, 4:31 AMHawk
11/07/2017, 4:32 AMandyr
11/07/2017, 9:12 AMpatrickdelconte
11/07/2017, 9:29 AMarthur
11/07/2017, 11:28 AMchristophsturm
11/07/2017, 1:49 PMSlackbot
11/07/2017, 4:44 PMKartik Shandilya
11/07/2017, 5:38 PMcdurham
11/07/2017, 6:52 PM@Throws
serve a purpose other than java interop?kevinmost
11/07/2017, 7:52 PMreturn lines.joinToString(separator = if (newLine) separator else "")
tiare.balbi
11/08/2017, 7:05 AMhelpermethod
11/08/2017, 12:42 PMoleksiyp
11/08/2017, 2:37 PMkevinmost
11/08/2017, 8:22 PMabstract
member, that's used as the default if an implementation doesn't override itradityagumay
11/09/2017, 2:13 AMbreak or continue jump across class boundary kotlin
this problem appears when i am going to use break or continue. inside lamda with receiver i create ‘letIn’
lamda with receiver code
fun letIn(componentName: String?, values: List<LifeService.Value?>?,
body: (String, List<LifeService.Value?>) -> Unit) {
if (!TextUtils.isEmpty(componentName) && (values != null && values.isNotEmpty())) {
body(componentName!!, values)
}
}
this sample code for it.
for (option in 0 until optionsSize) {
val component = optionsGroup?.options?.get(option)
component?.let {
with(component) {
letIn(presentation, values, { componentName, values ->
if (componentName == LifeComponentViewType.CHECKBOX) {
letIn(transformCheckBoxValues(optionsGroup), { data ->
dataSource?.push(componentName, ComponentDataCheckBoxCollection(name, data))
view.buildComponent(componentName)
// break or return doesnt work
})
} else {
dataSource?.push(componentName, ComponentDataCollection(name, values))
view.buildComponent(componentName)
}
})
}
}
}
because above code didnt work so i use imperative way.
for (option in 0 until optionsSize) {
val component = optionsGroup?.options?.get(option)
if (component != null) {
val presentation: String? = component.presentation
val values = component.values
if (!TextUtils.isEmpty(presentation)) {
if (presentation == LifeComponentViewType.CHECKBOX) {
val data = transformCheckBoxValues(optionsGroup)
if (data.isNotEmpty()) {
dataSource?.push(presentation, ComponentDataCheckBoxCollection(optionsGroup.name, data))
view.buildComponent(presentation)
return
}
} else {
dataSource?.push(presentation!!, ComponentDataCollection(component.name, values))
view.buildComponent(presentation!!)
}
} else {
return
}
}
}
does anyone have suggestions?bj0
11/09/2017, 3:25 AMfun <T: Foo> T.common() = this
diesieben07
11/09/2017, 9:05 AMfatih.yalmanbas
11/09/2017, 11:34 AMclass x{
val field;
X?.foo(){
this.field = doSomething();
}
}
fatih.yalmanbas
11/09/2017, 11:34 AMclass x{
val field;
X?.foo(){
this.field = doSomething();
}
}
snrostov
11/09/2017, 11:36 AMthis@x.field = doSometing()
(If I correctly understand what you need)fatih.yalmanbas
11/09/2017, 11:37 AM