Alec Muffett
12/02/2020, 10:06 AMProtobuf
and Square's Wire
to serialise data, and to deserialise into Kotlin.
Just like the example at https://github.com/square/wire#protocol-buffers I have a common Dinosaur
message which has got a name
string
The first and obvious change in the direction that I want to go, would be to replace the name
with a protobuf enum
so that I get Dinosaur.STEGOSAURUS
(etc) as a nameEnum, which means that the code can find out the soft-type of the message; but that doesn't give me what I want.
The second approach would be to use the protobuf oneof
type - and it would essentially do exactly the same soft-type thing - I could use Dinosaur.STEGOSAURUS.foo.bar
- but that still does not give me what I want.
What I want is for the deserialisation process of a Dinosaur
message to yield a Stegosaurus
type; or a TRex
or Apatosaurus
type, or whatever, so that resulting code can guarantee having an Apatosaurus
passed into it. I am presuming that some sort of DinosaurParser.peekType()
and DinosaurParser.getApatosaurusOrThrow()
will be needed, along with a type-enforcement is/as
check.
But that leaves me with the question of delegation so that I can access the other fields of the Dinosaur
message, like height, weight, etc.
• what's the best way for me to convert a "Dinosaur-message-with-TRex-soft-type" in the serialisation domain
• into a kotlin-domain strongly-typed-instance-of-TRex
that the compiler can check
• but also inherit (delegate?) all the accessors and methods from the underlying Dinosaur
message, into the TRex
instance?
It would be nice to do:
class TRex(d: Dinosaur) : Dinosaur by d
...however the protobuf compilers are generating Dinosaur
classes, not interfaces, so I don't think that option is open to me?Nick
12/02/2020, 10:44 PMnkiesel
12/02/2020, 11:00 PMprivate const val TIME_OUT = 10000 // in milliseconds
private val config = RequestConfig.custom()
.setConnectTimeout(TIME_OUT)
.setConnectionRequestTimeout(TIME_OUT)
.setSocketTimeout(TIME_OUT)
.build()
I only need TIME_OUT
for this initialization. How can I avoid having it hanging around? One idea I had was
private val config = 10_000.let { timeOut ->
RequestConfig.custom()
.setConnectTimeout(timeOut)
.setConnectionRequestTimeout(timeOut)
.setSocketTimeout(timeOut)
.build()
}
but that is not pretty either. Are there better ways?sindrenm
12/03/2020, 9:36 AMkotlinCompilerClasspath
would downgrade my Kotlin version from 1.4.20 → 1.4.10, or could perhaps point me in the right direction on where to look?
I see this when I run `./gradlew dependencies`:
kotlinCompilerClasspath
+--- org.jetbrains.kotlin:kotlin-compiler-embeddable:1.4.20 -> 1.4.10
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.10
| | +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.4.10
| | \--- org.jetbrains:annotations:13.0
| +--- org.jetbrains.kotlin:kotlin-script-runtime:1.4.10
| +--- org.jetbrains.kotlin:kotlin-reflect:1.4.10
| | \--- org.jetbrains.kotlin:kotlin-stdlib:1.4.10 (*)
| +--- org.jetbrains.kotlin:kotlin-daemon-embeddable:1.4.10
| \--- org.jetbrains.intellij.deps:trove4j:1.0.20181211
\--- org.jetbrains.kotlin:kotlin-compiler-embeddable:1.4.10 (*)
There are no (direct) references to 1.4.10 in my dependency declarations, either. And that's the only place where I see the downgrade to 1.4.10.
My Kotlin dependencies:
object Kotlin {
const val version = "1.4.20"
const val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version"
const val stdLib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$version"
}
Joao Birk
12/03/2020, 3:01 PMprivate fun CharSequence.split(delimiter: String, ignoreCase: Boolean, limit: Int): List<String> {
require(limit >= 0, { "Limit must be non-negative, but was $limit." })
var currentOffset = 0
var nextIndex = indexOf(delimiter, currentOffset, ignoreCase)
if (nextIndex == -1 || limit == 1) {
return listOf(this.toString()) -- HERE IT IS
}
Is this a behavior i should expect?SanbosayDev
12/03/2020, 3:30 PMNir
12/03/2020, 3:42 PMInt
. This seems like a pretty odd choice. Is there any way to instead have the standard library use a 64 bit integer?Patrik Åkerfeldt
12/03/2020, 5:34 PMannotation class MyAnnotation(val someValue: String, val optionalClass: KClass<*> = MyDefaultImplementation::class)
interface MyInterface {
fun doSomething(input: Any?): Any?
}
class MyDefaultImplementation: MyInterface {
override fun doSomething(input: Any?): Any? = input.toString()
}
How can I set a bound on optionalClass
to make sure only a class which implements MyInterface
is provided?Pratik Tandel
12/03/2020, 10:56 PMenum
? asking because i’m trying to figure out how swagger annotations work and if i can rename themKV
12/04/2020, 5:31 AM1.1.1
to 1.1.2
and in this version I stopped the rollout because we found out that there is some bugs. So I created the new branch hotfix/1.1.2
from the release/1.1.2
branch and merge the changes into release/1.1.2
branch.
But now the question is
1. Is this correct to fix the issue on the release/1.1.2
branch?
2. What version we should use for the hotfix release? should we use release/1.1.2
or release/1.1.3
?
3. Should we merge the hotfix
branch to release/1.1.2
branch or first do we need to create the new branch release/1.1.3
and merge hotfix changes into new branch?Paul Woitaschek
12/04/2020, 7:24 AM(200.days + 5.nanoseconds - 200.days).toLongNanoseconds()
This evaluates to 4
, not 5
.Mark
12/04/2020, 7:35 AMString.replace(String, String)
for an unlikely replacement, does it ever makes sense to wrap in a CharSequence.contains(CharSequence)
call, for efficiency?Julius Marozas
12/04/2020, 12:08 PMsealed class Fruit {
object Apple : Fruit()
object Orange : Fruit()
}
fun <T : Fruit> eat(fruit: T): Unit =
// 'when' expression must be exhaustive, add necessary 'else' branch
when (fruit) {
is Fruit.Apple -> {}
is Fruit.Orange -> {}
}
This is just a contrived example, I know that I could simply inline 'T' with 'Fruit'. I am more interested to understand why Kotlin fails to see that the 'when' expression is exhaustive.grahamborland
12/04/2020, 2:16 PMfrogger
12/04/2020, 2:20 PMMap<K,V?>
to Map<K,V>
? I.e. filter all null values and cast the map?Nir
12/04/2020, 7:25 PMinline
, so perhaps you'd want the sequence version to call the iterable version?Dieter Konrad
12/04/2020, 7:37 PMDieter Konrad
12/04/2020, 9:24 PM_shtomar
12/04/2020, 10:37 PMbjonnh
12/05/2020, 7:03 PMLastExceed
12/06/2020, 2:09 PMList<String>
that i'd like to split into a List<List<String>>
by indicating a delimiter String
, similar to how i can split a String
into a List<String>
by indicating a delimiter Char
using .split()
. unfortunately lists dont have a .split()
function, so what would be the best way to implement it ? looking for a functional approach if possiblejulian
12/06/2020, 5:33 PMinterface A {
val na: Int
}
class B {
val <T: A> T.nb: Int by lazy {
<http://this.na|this.na> // !!! I want to reference T/A here, not B.
}
}
I want to reference T : A
but the compiler won't let me. this
-s type is B
. Is there another way?Ekaterina Volodko [JB]
12/07/2020, 11:52 AMVivek Modi
12/07/2020, 12:49 PMNowak
12/07/2020, 3:24 PMval chainReactions: ChainReactions = mutableMapOf()
typealias ChainReactions = MutableMap<DomainEvent, DomainEvent>
Javier
12/07/2020, 6:48 PMThread.currentThread()
to obtain the line number, the problem is when I use a inline fun
this number is not valid and I can’t see a pattern to fix it. Is there a workaround to this problem?StavFX
12/07/2020, 7:07 PM@JvmOverloads
e.g.
class Foo(s: String? = null, i: Int = 3) // `new Foo();` from Java compiles
However, that’s not the case when using a secondary constructor
e.g.
class Foo {
constructor(s: String? = null, i: Int = 3) // `new Foo();` from Java does not compiles
}
Is this behavior documented somewhere? I couldn’t find anything..Philipp Mayer
12/07/2020, 9:08 PMvar label = when {
..someConditions.. -> "someString"
else -> ""
}
regexes.forEach {
label = label.replace(it.toRegex(), "").trim()
}
return label
I should maybe just step away from it for some time.. 😄
any hint is appreciated, thanks!Simon Lin
12/08/2020, 2:07 AM~/AndroidStudioProjects/
. How about non-android project?Brian Dilley
12/08/2020, 4:28 AMBrian Dilley
12/08/2020, 4:28 AMRob Elliot
12/08/2020, 7:23 AMBrian Dilley
12/08/2020, 8:45 AMRob Elliot
12/08/2020, 9:00 AMBrian Dilley
12/08/2020, 9:04 AM