pakoito
10/14/2017, 12:01 PMartem_zin
10/15/2017, 6:57 AMraulraja
10/24/2017, 8:07 PMReified
instance. For example:
package foo
interface Reified<A> {
val selfClass: KClass<A>
}
package bar
object ReifiedString: Reified<String> {
val selfClass: KClass<String> = String::class
}
import bar.ReifiedString
fooTC<String>() // compiles and returns String::class
fooTC<Int>() // Does not compile because the compiler can't find evidence of `Reified<Int>` imported in scope
dmitry.petrov
10/26/2017, 3:28 PMtypeOf<T>()
that will get you a generic JVM type, but it'd cost a class file for each call site at the moment.
--- That's getKType from the gist above ;)dmitry.petrov
10/26/2017, 3:36 PMSome::type
currently can resolve to a member reference for Some.type
mbstavola
10/26/2017, 5:46 PMfun foo(): Unit
it'd become void foo()
in Java rather than Unit foo()
when given a particular annotation. I think it'd make calling Kotlin code from Java a bit more pleasant.mbstavola
10/28/2017, 2:13 AMAndreas Sinz
10/28/2017, 11:57 AMkevinmost
11/03/2017, 2:59 PM@Contract(pure = true)
(an annotation from the Jetbrains annotation package), not sure if that works in Kotlin too?trevjones
11/04/2017, 7:37 PMraulraja
11/05/2017, 8:25 PMpakoito
11/07/2017, 7:25 PMkatz
11/14/2017, 11:11 AMkarelpeeters
11/16/2017, 11:44 AMstatic
keyword but less clear?kirillrakhman
11/16/2017, 11:52 AM@JvmStatic
to the companion object.arekolek
11/19/2017, 2:09 PMelect
11/22/2017, 10:30 AMvalueChanged |= whatever()
introduced on kotlin side a bug, whatever()
was never executed when valueChanged == true
, (valueChanged = valueChanged || whatever()
solved by flipping the or operands)galex
11/23/2017, 5:52 AMinline fun <reified T> logd(message: String) {
if (BuildConfig.DEBUG) {
Log.d(T::class.java.simpleName, message)
}
}If used without a specified type, the compiler will complain:
To fix this we need to specify the type:logd("abandonAudioFocus() called") // type inference failed: Not enough information to infer parameter T in (...). Please specify explicitly.
Wouldn’t it be convenient if the compiler would infer the type of the class this code is called in in this case? Maybe with a new inline keyword ?logd<PlayerManager>("abandonAudioFocus() called")
gregd
11/29/2017, 9:24 AMinterface Foo<T, U = Unit, V = Unit>
or even:
interface Foo<T, U = Unit, V = T>
This way, if you don’t care about some parameters, you could write:
class Bar : Foo<Int>
instead of:
class Bar : Foo<Int, Unit, Unit>
So far I’ve seen it in C++ and TypeScript, and it seems to work well.
What do You think?poohbar
11/30/2017, 3:54 PMstr.replace(""""""", """\""""")
how about
str.replace(`"`, `\"`)
rrader
12/01/2017, 7:52 AMfun main(args: Array<String>) {
val str = "--\"--"
println(str)
println(str.replace("\"", "\\\""))
}
bob
12/04/2017, 7:39 AMif?(state?.isValid)
instead of if(state?.isValid == true)
So when we have an if-statement of an nullable value we don’t have to explicitly declare the == true
all the time.natpryce
12/04/2017, 7:58 AMif (state?.isValid ?: true) ...
benleggiero
12/10/2017, 2:23 AMlouiscad
12/10/2017, 1:23 PMarg()
and 'arg?'()
(the single quotes being backticks, just Slack limitation), but the IDE says ?
is not allowed in identifiers in Android projects. So I added the JvmName("argOfNullable")
, but the IDE still complains, and I assume the compiler will too.
So, please, could you add the ability to apply the identifier restriction only on the JVM name in the nearest Kotlin release possible?shiraji
12/11/2017, 1:52 AMstatic import
?bob
12/12/2017, 7:31 AMtypealias
to that explicit typealias
. Even if the compiler later removes all type aliases they could (and should?) first be enforced.
typealias Degree = Double
typealias Radian = Double
fun Degree.toRadian():Radian = // Implementation
fun Radian.toDegree():Degree = // Implementation
fun run(degree:Degree) {
// should only be able to call toRadian and not toDegree on this parameter.
degree.toDegree()
}
mikehearn
12/12/2017, 2:34 PMkarelpeeters
12/12/2017, 2:38 PMlist[0]
.karelpeeters
12/12/2017, 2:39 PMIterator
.karelpeeters
12/12/2017, 2:39 PMIterator
.voddan
12/12/2017, 2:47 PMkarelpeeters
12/12/2017, 2:49 PMvar a = 3
for (c in emptyList()) a = 5
println(a)
maybe?mikehearn
12/12/2017, 2:50 PMkarelpeeters
12/12/2017, 2:53 PMvarargs
I've done things like fun max(first: Int, varargs rest: Int) = ...
, not sure if that's possible in your use case.mikehearn
12/12/2017, 2:53 PMcedric
12/12/2017, 9:51 PMmikehearn
12/13/2017, 9:49 AMpdvrieze
12/13/2017, 1:35 PMmikehearn
12/13/2017, 3:04 PM