Matt
03/18/2019, 3:56 PMmatt tighe
03/19/2019, 6:13 PMdata class VersionCode(val code: String) {
val major: Int
val minor: Int
val patch: Int
init {
val (first, second, third) = code.substringAfter('v').split('.')
major = first.toInt()
minor = second.toInt()
patch = third.toInt()
}
}
Guru
03/20/2019, 4:42 AMivano
03/20/2019, 1:53 PMivano
03/20/2019, 1:54 PMgregorbg
03/20/2019, 5:21 PMDavid Holmes
03/20/2019, 6:26 PMString
and parses it to return some MyDataClass
, is it idiomatic in Kotlin to return MyDataClass?
which is null
if the input String doesn't match the pattern? Or should I use a Result
or throw an exception or something? In this case returning null
would happen "normally" and would not be exceptional in any wayNikolai
03/21/2019, 10:14 AMFredrik Pe
03/21/2019, 1:50 PMif (list?.isEmpty())
not allowed when if (list?.isEmpty() == true)
is? You are still not specifying null behaviour...ddlucas
03/21/2019, 3:58 PMNikolai
03/22/2019, 2:13 AMbuildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
}
repositories {
google()
jcenter()
}
The main thing what I don't understand is purpose of 'buildscript' section,
I mean why not put everything outside of this section? What is the difference between 'repositories' inside and outside 'buildscript' (btw where is another project included into parent 'app' and it have his own 'repositories' section inside his build.gradle file )?Erik Bylund
03/26/2019, 11:13 PModay
03/27/2019, 12:02 PMdavec
03/29/2019, 4:38 PMString
, for example) this would work fine. However in the case below where the return type is Any
, it doesn't work.
data class Foo(val name:String, val age:Int)
val sortModes = mapOf("name" to Foo::name, "age" to Foo::age)
val myList = listOf(Foo("Dog", 17), Foo("Cat", 12), Foo("Mouse", 3))
val sortFunc = sortModes["name"] ?: error("Not found") // returns KProperty1<Foo, Any>
println(myList.sortedWith(compareBy(sortFunc)) // <-- compiler error
What magic is required to get Kotlin to sort by a function reference that can return Any
?matt tighe
03/29/2019, 9:13 PMacraWrapper.logAndThrow()
logs some exception information and then just rethrows the exception
outside of just tricking it by returning an invalid value, that istipsy
03/30/2019, 1:37 AMMap<Class, Object>
? intellij suggests both Map<Class<Any>, Any>
and Map<Class<*>, Any>
as parameter type, but neither work when calling the method from javaHexa
03/31/2019, 12:48 AMSaurabh
04/01/2019, 8:16 AMtodun
04/01/2019, 8:27 AModay
04/03/2019, 10:10 AMobjects.name
from that list and use that array independentlyJM Santos
04/05/2019, 12:18 AMhho
04/05/2019, 8:16 AMjurajsolarml
04/05/2019, 2:37 PMursus
04/06/2019, 3:35 AMprivate val typeface = Typeface.create(Typeface.DEFAULT_BOLD, Typeface.BOLD)
class InitialsDrawable(val context: Context) : Drawable() {
private val textPaint = Paint().apply {
isAntiAlias = true
color = context.getAttr(R.attr.defaultTextColor)
textSize = context.resources.dpToPixels(11F)
typeface = @file:typeface <--------------
textAlign = Paint.Align.CENTER
}
Mahi
04/06/2019, 9:42 AMwhile (index < 3) {
index ++
val result = cakesList?.let{
if(index == 2) {
"HelloString"
} else {
2
}
}
println("result value = $result")
when(result) {
is String -> println(" result variable is a String")
is Int -> println(" result variable is Integer")
}
scottiedog45
04/06/2019, 7:13 PMSmallville7123
04/09/2019, 1:03 AM> java.lang.NullPointerException (no error message)
for v[0]!!::class.objectInstance
Smallville7123
04/09/2019, 1:58 AMfun ret() {
class a {
var empty: Int = 0
}
val f = arrayListOf<a>()
f.add(a()) // class a is explicitly specified
}
Smallville7123
04/09/2019, 4:06 AMSmallville7123
04/09/2019, 5:14 AMSmallville7123
04/09/2019, 5:14 AMserebit
04/09/2019, 5:28 AMSmallville7123
04/09/2019, 5:51 AMdiesieben07
04/09/2019, 6:53 AMInt
are used interchangeably. When passed as Any
it must be boxed. You can use https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/java-primitive-type.html to get the primitive java class from either boxed or unboxed.Smallville7123
04/09/2019, 6:58 AM