Pablo
10/21/2020, 9:52 AMPeter Ertl
10/21/2020, 10:16 AMDávid
10/21/2020, 10:22 AMfun <data T: MyInterface> T.doSomethig() = copy(...)
And I could get access to beautiful concepts like copy which comes with the data
modifier on a class.
Until this is functionality is implemented, do you know of a good way to do assert that the copy method exists in this scope?Peter Ertl
10/21/2020, 10:44 AMsuspend fun bla(): Unit = TODO()
repeat(10) {
runBlocking {
bla()
}
}
or do I need a suspendable version of repeat ("repeatAsync") ?
Daniel
10/21/2020, 1:35 PMlaunch
. How can I launch coroutines from a non-suspend function in a fire-and-forget way faster?Nick
10/21/2020, 2:10 PMlet
, apply
, also
etc.) use contract
which is marked as @Experimental
. @Vsevolod Tolstopyatov [JB] suggested to not use shared flow in this from the past event as SharedFlow
was still experimental. He specifically pointed out to wait for a stable version if you work for a bank. Well, I currently work for a bank and I am told not to use anything marked as @Experimental
. Since everything in standard.kt
uses contract
, does this mean these functions aren’t stable either?Daniel
10/21/2020, 5:50 PMLazar Ristic91
10/21/2020, 8:48 PMMindorks
- Android Online Course for Professionals
? Or maybe has other Courses to recommend?Nikhil
10/22/2020, 7:41 AMtaer
10/22/2020, 4:02 PMprivate val logger by OurLogger()
I have a delegate working perfectly for class properties.
class OurLogger {
operator fun provideDelegate(thisRef: Any, prop: KProperty<*>) = LoggingDelegate(thisRef.javaClass.name)
}
class LoggingDelegate(klassName: String) : ReadOnlyProperty<Any?, Logger> {
private val capturedLogger = LogManager.getLogger(klassName)
override fun getValue(thisRef: Any?, property: KProperty<*>): Logger = capturedLogger
}
I can't get it to work though for top level properties. It seems to be looking for a provideDelegate(thisRef: Nothing?, prop: KProperty<*>
which makes sense because it doesn't have a this. In my case, using the generated class that houses the static variable(aka, the fileNameKT) would be fine, but I can't figure out how to get the provideDelegate(thisRef: Any, prop: KProperty<*>)
vs provideDelegate(thisRef: Nothing?, prop: KProperty<*>)
to work. The second I make the thisRef Nothing, I can't do anything w/ it.
I looked at the implementation of Lazy
it seems to get away with it on the top level via an extension function kotlin.Lazy<T>.getValue(thisRef: kotlin.Any?, property: kotlin.reflect.KProperty<*>)
Any advice on the top-level stuff?user
10/22/2020, 4:11 PMBrian Dilley
10/22/2020, 11:27 PMbodiam
10/23/2020, 1:03 AMdata class Alert(val message: String)
val alerts : List<Optional<Alert>> = getAlerts()
// filter
val messages = alerts
.filter { it.isPresent }
.map {it.get().message }
mattinger
10/23/2020, 1:18 PMBen Madore
10/23/2020, 1:40 PMfun Boolean.err(errorMessage: String): Boolean {
if (!this) {
<http://logger.info|logger.info> { errorMessage }
}
return this
}
...
if ((queryParams.size != 2).err("Expect exactly two query params but got ${queryParams.size}")
|| (queryParams["o"] == null).err("Query param o must be populated")
|| (queryParams["p"] == null).err("Query param p must be populated")
) {
return badRequest().buildAndAwait()
}
Hamza
10/23/2020, 2:03 PMKotlin
Aw man
We at compile time
IntelliJ on fullscreen from side to side
Side-side to side
This task, an easy one
Compiling to bytecode tonight, night, night
bytecode tonight
Heads up
You see a method with more than one expression
Total shock fills your body
Oh, no, it's you again
I can never forget those line lines lines
Lines-lines-lines
'Cause, baby, tonight
We're gonna be writing Kotlin again
'Cause, baby, tonight
You grab your map, filter, and run again (run again-gain)
And run, run until it's done, done
Until the sun comes up in the morn'
'Cause, baby, tonight
We're gonna be writing Kotlin again (Kotlin again-gain)
hnOsmium0x0
10/23/2020, 4:09 PMBrian Dilley
10/23/2020, 6:21 PMKa Wing Chin
10/23/2020, 7:10 PMDispatchers
. I created an endless loop to create threads and see how the program will behave.
class MainActivity : AppCompatActivity() {
private val dispatcher: CoroutineContext = <http://Dispatchers.IO|Dispatchers.IO>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val cores = Runtime.getRuntime().availableProcessors()
println("Cores: $cores")
println("===============================")
endlessLoop()
}
fun endlessLoop() = runBlocking {
withContext(dispatcher) {
println(Thread.currentThread().name)
while(true) {
launch {
println(Thread.currentThread().name)
while(true) {
// endless loop
}
}
}
}
}
}
I got a phone with 4 cores and each core can handle 4 threads.
If I would run this Dispatchers.Default
. Then output will be:
DefaultDispatcher-worker-1
DefaultDispatcher-worker-2
DefaultDispatcher-worker-3
DefaultDispatcher-worker-4
I get this, because all cores got occupied and working at 100% to get it done and no more tasks are allowed to be added.
However if I run it with <http://Dispatchers.IO|Dispatchers.IO>
which has 64 threads in the pool, it will run all 64 threads.
I though it was 4 cores * 4 threads = 16 threads max. Can someone explain me why the program doesn't stop at DefaultDispatcher-worker-16?
zero_coding
10/23/2020, 7:57 PMliminal
10/23/2020, 8:32 PM.let {}
on a non-nullable instance?Maxim Jaffe
10/23/2020, 8:45 PMPacane
10/23/2020, 9:07 PMv79
10/24/2020, 11:32 AMstephanmg
10/24/2020, 11:36 AMGabriel
10/24/2020, 2:32 PMdf
10/24/2020, 2:48 PMorg.hibernate.HibernateException: Getter methods of lazy classes cannot be final: SomeEntity#getFoo
. The error is gone when I mark the property explicitly as open but from what I understood is that this should happen automatically with the jpa compiler plugin?william
10/25/2020, 2:30 PMList
type for return values or ImmutableList
? i don't want the downstream consumers to modify it (which either would provide). It kind of seems like an implementatino details that i am using ImmutableList
Tobi
10/25/2020, 6:47 PMpublic
), all in one module.
❓ Why are all other modules not affected although they do not declare public
modifiers for their classes and methods?ahmad abas
10/26/2020, 4:41 AM