Florian
10/04/2019, 7:43 PMconst val
can not be assigned any function calls, but as I found out from this SO question it's actually possible for some functions:
https://stackoverflow.com/questions/44921746/what-can-be-expressed-in-a-compile-time-constant-const-val
From the given answers, it's not completely clear to me what is the reason for that. Is it because these function calls are not actually translated to function calls by the compiler, but replaced for operators?Florian
10/05/2019, 6:08 PMlaneinit
throws defeat the purpose of null safety?Martin Nordholts
10/06/2019, 6:24 AMObserver
prefix in the second line below in order for SAM conversion to work, but not in the first line? The last parameter has identical declarations in these two cases.
MutableLiveData<String>().observeForever({ }) // No 'Observer' prefix necessary
MutableLiveData<String>().observe(this, Observer { }) // 'Observer' prefix necessary!
// Java declarations
public void observeForever(@NonNull Observer<? super T> observer) {
public void observe(@NonNull LifecycleOwner owner, @NonNull Observer<? super T> observer) {
Florian
10/06/2019, 1:28 PMFlorian
10/06/2019, 3:32 PMconst val
besides literals and other `const val`s?Tuang
10/07/2019, 8:37 AMclass AccessLog: Serializable {
companion object {
var LOG = "/usr/local/logs/access_log"
@Synchronized
fun write(domain: String, remoteIp: String, userId: Int) {
File(LOG).bufferedWriter().use { out ->
out.write("""domain: $domain remote_ip: $remoteIp user_id: $userId """)
}
}
}
Florian
10/07/2019, 8:02 PMconst val
1) optimizes the generated bytecode 2) can be used in annotations. My question: are there any other benefits over just using val
that I am missing?Slackbot
10/08/2019, 11:56 AMursus
10/09/2019, 7:17 PMFoo : Bar<Quax>
require Quax
to be public, i.e. internal not allowed?ursus
10/09/2019, 7:26 PMvictor mazeli
10/10/2019, 9:36 AMraj
10/10/2019, 6:38 PMKotlin could not find the required JDK tools in the Java installation '/usr/lib/jvm/java-8-openjdk-amd64/jre' used by Gradle. Make sure Gradle is running on a JDK, not JRE.* Try: Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/5.5/userguide/command_line_interface.html#sec:command_line_warnings
Bacho Kurtanidze
10/10/2019, 8:24 PMFlorian
10/10/2019, 8:57 PMIf a Kotlin file contains a single class (potentially with related top-level declarations), its name should be the same as the name of the class, with the .kt extension appended.Because IntelliJ/AS removes the
.kt
if the file contains only 1 classEsa
10/11/2019, 7:35 AMCoroutineScope(EmptyCoroutineContext).async {}
calls on the 3 slowest components of that function, and awaiting the results at the end, as well as optimizing the order of the calls.
However, this means that function and every function up to the controller /endpoint now has a suspend
qualifier, as well as the controller having a runBlocking {}
wrapped around the function (it doesn’t seem like a major issue to me, that endpoint has about a 3.5s runtime now).. And as this is my first foray into coroutines, I’m sort of anxious there’s some drawbacks to this I’m missing.Big Chungus
10/12/2019, 10:54 AMBacho Kurtanidze
10/12/2019, 5:49 PMPablichjenkov
10/13/2019, 11:35 PMfun extractRealClass(valueClass: Class<*>): Class<out PrimitiveWrapper<*>>? {
return when (valueClass) {
Boolean::class.java -> BooleanWrapper::class.java
Int::class.java -> IntWrapper::class.java
String::class.java -> StringWrapper::class.java
else -> null
}
}
// where PrimitiveWrapper is defined as:
open class PrimitiveWrapper<T>(val value: T) {... Above func lives in this class companion}
class BooleanWrapper(value: Boolean) : PrimitiveWrapper<Boolean>(value) { ... }
class IntWrapper(value: Int) : PrimitiveWrapper<Int>(value) { ... }
on another class Entry
I have this:
Entry<T: Any?>(
private val key: String,
private val clazz: Class<T>
) {
override fun getInstance(): T? {
// It always return null when calling above mentioned func.
val primitiveClass: Class<out PrimitiveWrapper<*>>?
= PrimitiveWrapper.extractRealClass(clazz)
}
}
Whenever I call the PrimitiveWrapper.extractClass(clazz)
with the save class info it always return null. I tried many things and no matter what in the when
block the coming class always print like int
or <http://kotlin.Int|kotlin.Int>
but never java.lang.Integer
. Could some body shed some light?harry.singh
10/14/2019, 11:41 AMFlorian
10/14/2019, 8:56 PMlateinit
or override the getter
. Any other ways to get around immediate initialization? (It's a theoretical question)Sudhir Singh Khanger
10/15/2019, 5:31 AMMap/MutableMap
which is a LinkedHashMap
which preserves the insertion order unlike HashMap
. In Java/Android, if one is used to using HashMap
then I would think I can continue using Map/MutableMap
in Kotlin. Is that correct?veesus mikel heir
10/15/2019, 11:33 AMveesus mikel heir
10/15/2019, 4:05 PMEllen Spertus
10/15/2019, 9:34 PMFlow
? I have not used React so lack that background, although I am familiar with streams from functional programming and have experience with asynchronous callbacks.Florian
10/16/2019, 2:07 PMclass
keyword + primary constructor
or only the primary constructor?
The Kotlin Docs use the latter definition (+ type parameters) but that's not what I have in mindSylvain Patenaude
10/16/2019, 2:39 PMMichał Kalinowski
10/16/2019, 4:16 PMNo type arguments expected for class List
Animesh Sahu
10/16/2019, 4:41 PMFlorian
10/17/2019, 8:08 AMinit
block under a property I can initialize it there. This doesn't seem to work anymore if this property has a setter. Is that correct?Martin Nordholts
10/17/2019, 1:48 PM!!
in below code without getting compilation errors and without getting ugly code? Edit: And without recursion
class Node(val child: Node?)
fun Node.getLeaf(): Node {
var candidate: Node = this
while (candidate.child != null) {
candidate = candidate.child!!
}
return candidate
}