phldavies
12/14/2018, 12:06 PMfun MyPojo.init(fieldName: String? = null) {
fieldName?.let(::setFieldName)
fieldName?.also { setFieldName(it) }
fieldName?.also { this.fieldName = it }
if(fieldName != null) setFieldName(fieldName)
if(fieldName != null) this.fieldName = fieldName
}
dmcg
12/14/2018, 1:37 PMxenoterracide
12/14/2018, 6:54 PMdependencies {
compile(kotlin("stdlib", "1.3.11"))
}
w: Runtime JAR files in the classpath have the version 1.2, which is older than the API version 1.3. Consider using the runtime of version 1.3, or pass '-api-version 1.2' explicitly to restrict the available APIs to the runtime of version 1.2. You can also pass '-language-version 1.2' instead, which will restrict not only the APIs to the specified version, but also the language features
w: /tmp/.gradle-test-kit-xeno/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.2.71/ba18ca1aa0e40eb6f1865b324af2f4cbb691c1ec/kotlin-stdlib-common-1.2.71.jar: Runtime JAR file has version 1.2 which is older than required for API version 1.3
w: /tmp/.gradle-test-kit-xeno/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.71/d9717625bb3c731561251f8dd2c67a1011d6764c/kotlin-stdlib-1.2.71.jar: Runtime JAR file has version 1.2 which is older than required for API version 1.3
e: /tmp/junit14078856699846774951/junit17290987759747338376/src/main/kotlin/com/xenoterracide/test/Test.kts: (17, 1): Cannot access script base class 'kotlin.script.templates.standard.ScriptTemplateWithArgs'. Check your module classpath for missing or conflicting dependencies
how do I make kotlin 1.3 work? or heck, even 1.2… no matter what I seem to do it seems to end up with this errorDico
12/14/2018, 8:15 PMtschuchort
12/14/2018, 10:59 PMthis
to a mixin class that implements an interface via delegation? (i.e. class Class : Interface by Mixin(this)
. It's possible to pass this
but for some reason it refers to the companion instead of the instance itself. I realize that I could just instantiate the mixin in the class body and delegate all methods manually, but that's quite annoying.Dalinar
12/15/2018, 8:22 AM`
private val requests: Cache<String, Req> = Caffeine.newBuilder()
.removalListener<String, Req> { clientOrderID: String?, req: Req?, removalCause: RemovalCause ->
clientOrderID!!; req!!
...
req.close()
}
`
with Guava the code would compile without the `?on the parameters
the reason I added these
!!where I did was because I refer to these variables several times in the code afterwards. However what I'm asking is if there is a nicer syntax where I can somehow get rid of the
?` on the parameters
very strange, my other similar caches built in the same way have no problem accepting non-nullable parameters in removalListener
- it's just this particular one that is the problemxenoterracide
12/15/2018, 8:44 AMxenoterracide
12/15/2018, 6:05 PMxenoterracide
12/15/2018, 6:06 PMsimon.vergauwen
12/16/2018, 12:26 PMDominaezzz
12/16/2018, 4:30 PMitnoles
12/16/2018, 6:19 PMaris
12/16/2018, 7:50 PMPaul Woitaschek
12/16/2018, 9:21 PMgroostav
12/17/2018, 1:52 AMCzar
12/17/2018, 1:12 PMpublic abstract <R> java.util.concurrent.CompletableFuture<R> send(Object command)
Java call
object.send(command);
nice 👍 :java:
Kotlin call
object.send<Any>(command)
not nice, I'd like to avoid having to write <Any>
👎 :kotlin:Paul Woitaschek
12/17/2018, 1:52 PMSlackbot
12/17/2018, 8:08 PMserebit
12/18/2018, 12:15 AMAmir
12/18/2018, 8:35 AMkarelpeeters
12/18/2018, 8:41 AMrrader
12/18/2018, 10:52 AMmikehearn
12/18/2018, 2:35 PMgrahamborland
12/18/2018, 3:34 PMprivate fun shouldNotCompile(optionalString: String?): Boolean {
optionalString?.let {
return true
}
}
I’ve completely forgotten to specify a return value for the case where the let
is not entered.grahamborland
12/18/2018, 3:40 PMcristiangm
12/18/2018, 5:12 PMSrSouza
12/18/2018, 6:20 PM@ExperimentalContracts
?Rohan Maity
12/18/2018, 10:52 PMtipsy
12/19/2018, 9:29 AMType inference failed: Not enough information to infer parameter X in
fun <R : Any!, X : Exception!> withHandle(callback: ((handle: Handle!) → R!)!): R!
Please specify it explicitly.
the method signature is public <R, X extends Exception> R withHandle(HandleCallback<R, X> callback) throws X {
what am i supposed to do in this case?rrader
12/19/2018, 10:23 AMobject Users : Table() {
val id = varchar("id", 10).primaryKey() // Column<String>
val name = varchar("name", length = 50) // Column<String>
val cityId = (integer("city_id") references Cities.id).nullable() // Column<Int?>
}
Users.insert {
it[id] = "andrey"
it[name] = "Andrey"
it[cityId] = saintPetersburgId
}
how compiler know that it[id]
is valid and for example it[title]
is not valid?
from https://github.com/JetBrains/Exposedrrader
12/19/2018, 10:23 AMobject Users : Table() {
val id = varchar("id", 10).primaryKey() // Column<String>
val name = varchar("name", length = 50) // Column<String>
val cityId = (integer("city_id") references Cities.id).nullable() // Column<Int?>
}
Users.insert {
it[id] = "andrey"
it[name] = "Andrey"
it[cityId] = saintPetersburgId
}
how compiler know that it[id]
is valid and for example it[title]
is not valid?
from https://github.com/JetBrains/Exposedreik.schatz
12/19/2018, 11:00 AM.insert
is an extension function and then id
, name
and cityId
are just Column
instances given to the InsertStatement
val title: Column<?>
just doesn’t exists in your Users
objectrrader
12/19/2018, 11:03 AMUsers
and not from other object
?reik.schatz
12/19/2018, 11:06 AM.insert
is added to Users
fun <T:Table> T.insert(body: T.(InsertStatement<Number>)->Unit): InsertStatement<Number> = InsertStatement<Number>(this).apply {
body(this)
execute(TransactionManager.current())
}
T
is a specific typerrader
12/19/2018, 11:45 AMMike
12/19/2018, 1:48 PMinsert
is an extension function on all types. body
is a Lambda with receiver. Some more advanced Kotlin features that allow for powerful DSL’s.
Hopefully those keywords give you some direction for research.
But ultimately, the Lambda you’re passing to insert
(everything inside the {}) has a single parameter it
that is of the type of the class insert
is being called on.
So in this case, the compiler knows that it
is of type Users