harsh
11/23/2020, 6:59 PMKirill Grouchnikov
11/23/2020, 10:35 PMCollections.unmodifiableList
?Kirill Grouchnikov
11/23/2020, 10:37 PMKirill Grouchnikov
11/23/2020, 10:39 PMlistOf
creates a whole new list. Java's unmodifiableList
is a very thin wrapper that throws exceptions on trying to modify the contents of the wrapped listSlackbot
11/24/2020, 10:22 AMMejiomah17
11/24/2020, 11:32 AMBernhard
11/24/2020, 2:32 PMBernhard
11/24/2020, 2:57 PMinterface Importer {
fun run(value: String): String
}
val x = listOf(
Importer { it.replace("h", "o")}
)
Gives me this on Kotlin 1.4.20:
Interface Importer does not have constructors
Unresolved reference: itTomas Kormanak
11/24/2020, 3:03 PMPlugin org.jetbrains.kotlin:kotlin-maven-plugin:1.4 or one of its dependencies could not be resolved: Failure to find org.jetbrains.kotlin:kotlin-maven-plugin:jar:1.4
Am I missing something?manlan
11/24/2020, 5:43 PMNcrnomarkovic
11/24/2020, 7:15 PMChilli
11/24/2020, 11:53 PMAutoCloseable.use(...)
function? It should be there, according to the stdlib documentation...user
11/25/2020, 6:13 PMAkash Veerappan
11/25/2020, 10:17 PMIfvwm
11/26/2020, 7:02 AMclass OnlyAudioRecorder public constructor(val hadoopAddr: String, val kafkaAddr: String ){
companion object{
val instance:OnlyAudioRecorder by lazy (mode = LazyThreadSafetyMode.SYNCHRONIZED){
OnlyAudioRecorder(hadoopAddr, kafkaAddr)
}
}
// why this hadoopAddr and kafkaAddr are not referenced?
Cicero
11/26/2020, 12:57 PMabstract class AbstractResourceTopic(val state: ResourceState? = null, val isOn: Boolean? = null) {
abstract val resourceType: ResourceType
}
and this
fun AbstractResourceTopic.getIcon(): Int {
this.state?.let {
return when (it.state) {
0 -> getStateZeroIcon()
1 -> getStateOneIcon()
2 -> getStateTwoIcon()
else -> getStateZeroIcon()
}
}
this.isOn?.let {
return if (isOn) getOnIcon() else getOffIcon()
}
return getStateZeroIcon()
}
I turned into this
abstract class AbstractResourceTopic {
constructor(state: ResourceState)
constructor(isOn: Boolean)
abstract val resourceType: ResourceType
}
and I don’t know how to create extension classes for this two different constructors
fun AbstractResourceTopic.getStateIcon(): Int {
return when (it.state) {
0 -> getStateZeroIcon()
1 -> getStateOneIcon()
2 -> getStateTwoIcon()
else -> getStateZeroIcon()
}
}
}
fun AbstractResourceTopic.getIsOnIcon(): Int {
return if (isOn) getOnIcon() else getO
}
This is not working and I couldn’t find the correct syntax or if I can even do thisribesg
11/26/2020, 2:23 PMvararg
of inline class
type?Jrichards1408
11/26/2020, 2:49 PMMartin Barth
11/26/2020, 3:19 PM!!
all over the place?
val extractor = when {
config.contains(REGEX) && config.contains(FORMAT) -> FormatAndRegexExtractor(config[REGEX]!!, config[FORMAT]!!)
config.contains(REGEX) && !config.contains(FORMAT) -> NamedCaptureGroupExtractor(config[REGEX]!!)
config.contains(DELIMS) && config.contains(FIELDS) -> DelimiterExtractor(config[DELIMS]!!, config[FIELDS]!!)
else -> throw IllegalArgumentException("can not process this configuration: $config")
}
allan.conda
11/26/2020, 5:07 PMnull
in Kotlin?
fun <T> aFunctionWithOptionalParam(
optionalParam: T? = null
) {
if (/* optionalParam is set*/) {
someCallbackIfSet()
}
}
fun whatIWant() {
aFunctionWithOptionalParam(1) // callback is invoked
aFunctionWithOptionalParam(null) // callback is invoked
aFunctionWithOptionalParam() // callback should not be invoked
}
Ifvwm
11/27/2020, 3:21 AMval instance:OnlyAudioRecorder by lazy (mode = LazyThreadSafetyMode.SYNCHRONIZED){
OnlyAudioRecorder(h,k)}
// what does by lazy (mode = ...) { ... } mean? should lazy take a lambda? but (...) {...} is not a lambda
Ifvwm
11/27/2020, 5:11 AMCharlie Brown
11/27/2020, 7:09 AM//Consider the code snippet below. What will it print?
var num = 0
println(num++ + ++num)
Here is my step
num++ + ++num (num = 0)
num++ + 1 (num = 1)
1 + 1 (num = 1)
Am i correct?German Politov
11/27/2020, 10:08 AM<http://java.io|java.io>.InputStream
in Kotlin? When I converted Java class(that had InputStream
type field) to Kotlin that field was accessible in Kotlin, but when I created a new Kotlin class in Kotlin project InputStream was not accessible like it's presented on screenshot.t0yger
11/27/2020, 10:22 AMinterface Test {
val a: String
}
var Test.b: String
get() = field
set(value) = field = value
Ivan Pavlov
11/27/2020, 11:38 AMfun
interface with lambdas (class D
) doesn't work? I'd really want to use delegation that way, not like class C
fun interface A {
fun f()
}
fun interface B {
fun f()
}
class C(b: B) : A by A(b::f) //works
class D(b: B) : A by { b.f() } //doesn't work
user
11/27/2020, 2:23 PMNikky
11/27/2020, 8:09 PMexitProcess(0)
but it does not.. when i run this from within idea it just hangs at the endChilli
11/27/2020, 8:52 PMChilli
11/27/2020, 9:42 PMChilli
11/27/2020, 9:42 PMDominaezzz
11/27/2020, 9:43 PMChilli
11/27/2020, 9:49 PMDominaezzz
11/27/2020, 9:50 PMzip
might help?Tobias Berger
11/27/2020, 9:51 PMprevious()
function. Peeking (looking at the next element without progressing) is not included, which might be a good thing because in some cases it could lead to unexpected behaviour. However, you could implement your own "PeakingIterator" (or use the one from apache commons if you're on JVM)Nir
11/27/2020, 9:55 PMChilli
11/27/2020, 9:56 PMTobias Berger
11/27/2020, 10:05 PMNir
11/27/2020, 10:09 PMokarm
11/27/2020, 10:10 PMTobias Berger
11/27/2020, 10:10 PMpeek()
and there are no more elements. A check for that could be added easily if you want that behaviour
@Nir you're not having a stroke (I hope), I just had a brain fart when writing the classNir
11/27/2020, 10:10 PMTobias Berger
11/27/2020, 10:14 PMAbstractIterator
implementation and exposing nextValue
(or something that would look very similar). I wouldn't have written it like above myself, but it is shorter and part of a widely used Google lib, it should be ok.Nir
11/27/2020, 10:17 PMclass PeekingIterator<T>(private val iterator: Iterator<T>) : Iterator<T> {
fun Iterator<T>.nextOrNull() = if (iterator.hasNext()) iterator.next() else null
var nextElement = iterator.nextOrNull()
override fun hasNext() = (nextElement != null)
override fun next(): T {
val next = nextElement!!
nextElement = iterator.nextOrNull()
return next
}
fun peek() = nextElement
}
Tobias Berger
11/27/2020, 10:19 PMPeakingIterator<T: Any>
(not allowing nullable types). Having null values would break this implementationNir
11/27/2020, 10:20 PMTobias Berger
11/27/2020, 10:20 PMoverride fun next(): T {
val next = nextElement ?: throw NoSuchElementException()
...
Nir
11/27/2020, 10:20 PMTobias Berger
11/27/2020, 10:22 PMnull
and undefined
Nir
11/27/2020, 10:25 PMTobias Berger
11/27/2020, 10:25 PMnull
for an optional parameter that also has null
as its default value. Same issue.Nir
11/27/2020, 10:25 PMTobias Berger
11/27/2020, 10:27 PMnull
can actually be an expected value.?.let
, ?:
, etc.Nir
11/27/2020, 10:34 PMTobias Berger
11/27/2020, 10:38 PMNir
11/27/2020, 10:39 PM