Ruckus
02/17/2017, 4:52 PMcoroutines-guide.md
)kirillrakhman
02/20/2017, 4:09 PMobject Name {
operator fun provideDelegate(thisRef: Any?, property: KProperty<*>) = property.name
}
operator fun String.getValue(thisRef: Any?, property: KProperty<*>) = this
val foo by Name
fun main(args: Array<String>) {
println(foo) //prints "foo"
}
jackmiras
02/20/2017, 4:10 PMdhkim
02/21/2017, 1:00 PMfun func(a: Any?) {}
fun <T> func(a: Collection<T>) {}
fun main(args: Array<String>) {
func(null) // Type inference fails here
}
jackmiras
02/21/2017, 1:57 PMoverride fun post(req: Request, res: Response): Any {
val platform = req.bodyAsObject() as Platform
if (platform.isValid()) {
PlatformRepository().save(platform)
return object { val message = "Platform created" ; val status = 201 }
} else {
return renderInvalidParams()
}
}
I could avoid doing the if else
statement by using functions as callback... just like this:
override fun post(req: Request, res: Response): Any {
req.bodyAsObject(success = {
PlatformRepository().save(platform)
return object { val message = "Platform created" ; val status = 201 }
}, failure = {
return renderInvalidParams()
})
}
xolan
02/21/2017, 1:58 PMapply plugin: 'kotlin'
apply plugin: 'application'
apply plugin: 'org.junit.platform.gradle.plugin'
buildscript {
ext.kotlin_version = '1.0.6'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M3'
}
}
---snip---
FAILURE: Build failed with an exception.
* Where:
Build file '/home/xolan/work/accounter/build.gradle' line: 1
* What went wrong:
A problem occurred evaluating root project 'accounter'.
> Failed to apply plugin [id 'kotlin']
> For input string: ""
Any suggestions? Can't seem to figure this one outjackmiras
02/21/2017, 1:59 PMdhkim
02/21/2017, 2:07 PMorangy
02/22/2017, 12:24 AMdragas
02/22/2017, 10:30 AMreminderSubscription?.unsubscribe()
instead?robin
02/22/2017, 12:05 PMval unwrapped = optional
if(unwrapped != null) { doSmth() }
else { doSmthElse() }
robin
02/22/2017, 12:32 PMjohnl
02/22/2017, 12:36 PMjohnl
02/22/2017, 1:02 PMsomoni
02/22/2017, 2:57 PMrepositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
}
orangy
02/22/2017, 7:31 PMccrowe
02/22/2017, 9:23 PMdalexander
02/22/2017, 9:49 PMval obj: Any = "asdf"
when(obj) {
is Int -> println("Int!")
is Double -> println("Double!")
is String -> { println("String!") } // you can add braces if you have a longer statement
}
groostav
02/23/2017, 10:57 AMError: Kotlin: Multiple values are not allowed for plugin option org.jetbrains.kotlin.kapt:outputPlugin
orangy
02/23/2017, 10:59 AMnkiesel
02/23/2017, 7:58 PMmap["hello"]
can be written as map.hello
(as long as the key is a valid identifier). That's Lua's way to compensate for not having classes with properties. The by map
property delegate in Kotlin does something similar, but requires to explicitly list all the properties. Any chance that Kotlin would be able to do the same?groostav
02/23/2017, 11:47 PMval x by map
was that it would primarily operate on objects of disparate types (a le Javascript), thus I think the by map
idea was largely aimed as a shim for dynamic languages into kotlin.
But I could agree with your assestment, especially when we have access to raw types. Perhaps it would be better if we had something like
val map: Map<String, Any?> = ...
val name:String by map //compiler error: cannot use `Map<String, Any?> as delegate for `val name: String` expected Value type to be String but was Any?
val name: String by (map as Map) //compiler warning: unchecked raw type cast: Map<String, Any?> to Map
val name: String by @SuppressWarnings("unchecked")(map as Map) //compiles without issue
unfortunately its a moot point since any change would break backwards compatibility in a pretty big wayjackmiras
02/24/2017, 4:22 PMcurioustechizen
02/25/2017, 2:07 PMsreich
02/25/2017, 5:25 PMuli
02/26/2017, 11:08 AMsreich
02/26/2017, 12:55 PMwhen (foo) { != 0 -> stuff(); else -> blah() }
, while still using the var specifier, aka the (foo)
mikehearn
02/26/2017, 3:49 PMadibfara
02/27/2017, 7:45 AMmiha-x64
02/27/2017, 10:33 AMinner object
? private inner object Thing : Something {
looks logically similar to private val thing = object : Something {
...miha-x64
02/27/2017, 10:33 AMinner object
? private inner object Thing : Something {
looks logically similar to private val thing = object : Something {
...groostav
02/27/2017, 10:51 AM