ziggy42
03/19/2018, 12:11 PMtypealias Listener<T> = (T) -> Unit
and for each T
that I accept I need to store the list of registered listeners: val userListeners = mutableListOf<Listener<User>>()
. But this forces me to have N lists for N possible T
. Is there a better way?poohbar
03/19/2018, 1:54 PMClass<PersonKotlin> klass1 = PersonKotlin.class;
KClass<PersonKotlin> kotlinClass1 = JvmClassMappingKt.getKotlinClass(klass1);
Class<PersonJava> klass2 = PersonJava.class;
KClass<PersonKotlin> kotlinClass2 = JvmClassMappingKt.getKotlinClass(klass2); // error
Although the types of klass1
and klass2
are identical the compiler recognizes that I can't call getKotlinClass
on a Java class. How does it do that?Michael
03/19/2018, 2:18 PMCriteria criteria = new Criteria(new Filter(new Filter.FilterConditions("field", "value", FilterConditionOperator.EQ)))
The “FilterConditionOperator” thing really annoys me - and I don’t think I’ve seen a way to sort of “force a static `import`“, right? Would the “idiomatic Kotlin” way to go be maybe to make an infix function for each of the enum values, as a FilterConditionFactory?ziggy42
03/19/2018, 2:40 PMListener<T>
is Listener<User>
?karelpeeters
03/19/2018, 3:26 PMnfrankel
03/19/2018, 3:56 PMSituations
03/19/2018, 4:11 PMMichael
03/19/2018, 4:39 PMpoohbar
03/19/2018, 5:04 PMjava.lang.Class
from kotlin.reflect.KClass
?SrSouza
03/20/2018, 7:10 AMyusuf3000
03/20/2018, 8:33 AMenum Constants {
static let randomNumber: Int = 42
static let randomString = "42"
static let randomNonPrimitiveType = CustomClass(number: 42)
}
Then use it like so:
let constantsUse = Constants.randomNonPrimitiveType
What’s the best way to do this in Kotlin? Especially if the constant is a non primitive type.robstoll
03/20/2018, 11:50 AMGarouDan
03/20/2018, 2:39 PMmutexkid
03/20/2018, 6:50 PMGarouDan
03/20/2018, 8:57 PMDominik
03/20/2018, 9:17 PMDominik
03/20/2018, 9:22 PMKarolo
03/20/2018, 11:17 PMjmschultz
03/20/2018, 11:20 PMalbertgao
03/21/2018, 12:28 AMa.b.c
, I have an abstract
class named BaseUser
which I use it to share some code. But I want this class BaseUser
to be internal in the a.b.c
. Such that, I can create User:BaseUser
in a.b.c
. But the user of package can’t refer a.b.c.BaseUser
. I tried the protected
modifier. Not work, when I try to build, it said This type is final, so it cannot be inherited from
, Cannot access 'BaseUser': it is protected in 'a.b.c'
and 'public' subclass exposes its 'protected (in ?)' supertype BaseUser
.
No luck with internal
too
How to make this work? 🤔benny.huo
03/21/2018, 8:37 AMedwardwongtl
03/21/2018, 10:21 AMException e
-> e: Exception
brescia123
03/21/2018, 10:41 AMSlackbot
03/21/2018, 11:25 AMkarelpeeters
03/21/2018, 2:13 PMReturns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.)But it looks like using this property is not possible from Kotlin since you can't pass the real array.
janvladimirmostert
03/21/2018, 2:50 PMval mythread = thread { .... some code here that runs in this thread ... }
... more code here ...
while (mythread.isAlive) {
Thread.sleep(10)
}
do something else that depends on things setup during the thread
robstoll
03/21/2018, 4:22 PMval list = mutableListOf()
var parent = map[current]
while(parent != null){
list.add(parent)
parent = map[parent]
}
I have the feeling there is a functional equivalent but I cannot come up with what it isSlackbot
03/21/2018, 6:49 PMadams2
03/22/2018, 1:24 AMsealed class Foo { object BAR : Foo() }
or sealed class Foo { object Bar : Foo() }
romster
03/22/2018, 8:17 AMromster
03/22/2018, 8:17 AMCzar
03/22/2018, 9:50 AMromster
03/22/2018, 10:17 AMCzar
03/22/2018, 10:18 AMromster
03/22/2018, 10:19 AMCzar
03/22/2018, 10:34 AMFleshgrinder
03/22/2018, 10:35 AMromster
03/22/2018, 10:36 AMCzar
03/22/2018, 10:41 AMFleshgrinder
03/22/2018, 10:42 AMromster
03/22/2018, 11:07 AMCzar
03/22/2018, 2:53 PMdo not test private method, or make them publicIt's more like "Test all public methods, so that private ones don't need to be tested. If by testing the public method you cannot ensure correctness, and absolutely need to test private methods, then most probably there's something dangerously wrong in the design." I understand that
internal
stuff is not truly private and should be tested, that just means: keep your tests in the same module as your code./src/main/kotlin/com/example/InternalClass.kt
/src/test/kotlin/com/example/InternalClassTest.kt
Fleshgrinder
03/22/2018, 5:29 PMinternal
is different and you can easily test them. As I said, it's more cumbersome to set up compared to a proper package visibility and I would love to see it in Kotlin but right now that's what we have:
/lib/src/main/kotlin/com/example/PublicClass.kt
/lib/src/main/kotlin/com/example/InternalClass.kt
/lib/src/test/kotlin/com/example/PublicClassTest.kt
/lib/src/test/kotlin/com/example/InternalClassTest.kt
/app/src/main/kotlin/com/example/NoAccessToInternalClass.kt