bjonnh
04/27/2019, 7:45 PMursus
04/29/2019, 3:02 AMval foo1: String?
val foo2: String?
mapOf(
// if (foo1 != null) foo1 to 1 else ???
// if (foo2 != null) foo2 to 2 else ???
)
scottiedog45
04/29/2019, 8:03 PMLinearLayout
as an argument here, what’s going on?
fun <T : View> getView (viewType : T, id: Int) : T {
return view!!.findViewById<T>(id)
}
val l = getView(LinearLayout, R.id.settingsLanguageRow)
Dangelomjoyce
04/29/2019, 10:39 PMaarjav
05/02/2019, 8:41 PMpublic class Foo {
public class FooInner {
public final String key;
private FooInner(String key) {
this.key = key;
}
}
public FooInner wrap(String key) {
return new FooInner( key );
}
}
A hack that may work, but would rather keep constructor public than use: https://stackoverflow.com/a/18634125/5130921ursus
05/02/2019, 10:52 PMkrleg
05/03/2019, 9:49 AMHullaballoonatic
05/05/2019, 8:57 PMval self = this
and
val self get() = this
is the latter more expensive for no reason? are they the same?Hullaballoonatic
05/06/2019, 7:36 AM'public' function exposes 'private' return type
?Kristian
05/07/2019, 2:13 PMGoldrichs
05/08/2019, 4:08 PMGoldrichs
05/08/2019, 7:56 PMGoldrichs
05/08/2019, 8:03 PMcrummy
05/10/2019, 5:08 AMvar
?scottiedog45
05/10/2019, 10:02 AMKumaran Masilamani
05/10/2019, 7:41 PM//Given my ADT as follows ...
sealed class Result {
object Success : Result()
data class Failure(val reason: FailureReason) : Result()
enum class FailureReason { REASON1, REASON2 }
}
//I want to do something like this
when (result) {
is Success ->
is Failure(REASON1) ->
is Failure(REASON2) ->
}
In Scala I will use with a variable, but it didn't work in KotlinHullaballoonatic
05/10/2019, 8:43 PMkarelpeeters
05/11/2019, 5:54 PM<?>
stuff simple smileLucas
05/13/2019, 11:44 AMa b c d
iterated as a b; b c; c d
. This is to calculate the delta between elementsj_recuerda
05/13/2019, 2:09 PMAleks Clark
05/13/2019, 6:07 PMByteReadChannel
from ktor)Florian
05/14/2019, 1:48 PMjschneider
05/15/2019, 1:30 PMjschneider
05/15/2019, 1:30 PMQuinn
05/15/2019, 1:38 PMvar sources = spawn.room.find(FIND_SOURCES).sort { a,b ->
(a.pos.x - b.pos.x) * (a.pos.x - b.pos.x)
+ (a.pos.y - b.pos.y) * (a.pos.y - b.pos.y)}
val creepsWithSource1 = creeps.count { it.memory.assignedSource == sources[0].id }
val creepsWithSource2 = creeps.count { it.memory.assignedSource == sources[1].id }
val assignedSource = if(creepsWithSource1 < creepsWithSource2) sources[0].id else sources[1].id
This results in the following error message. I'm trying to decipher what this error means so I can understand it in the future.
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline operator fun <K, V> Record<Int, [ERROR : No type element]?>.get(key: Int): [ERROR : No type element]? defined in starter
Hullaballoonatic
05/15/2019, 6:19 PMBar
to be able to call foo()
and return its own typematt tighe
05/15/2019, 9:21 PMclass MyClass(instance: MyObject) {
val prop = instance.myFun()
}
would instance
be released as soon as construction had completed?crummy
05/15/2019, 11:14 PMfor (i in (0..100)) {
if (i == 10) i += 10
}
Mike
05/16/2019, 12:51 PMfun eval(expr: Expr): Int =
when (expr) {
is Num -> expr.value
is Sum -> eval(expr.left) + eval(expr.right)
else -> throw IllegalArgumentException("Unknown expression")
}
interface Expr
class Num(val value: Int) : Expr
class Sum(val left: Expr, val right: Expr) : Expr
What I don’t understand is the use of the “eval” . If you go look at the kotlin docs they say “don’t use! Really Bad!” And it seems like you would want to do something like expr.left.value + expr.right.value. But it doesn’t know if left and right are Expr or Num. So you should be able to explicitly cast, but then you have to check to make sure it is the right type. It gets very messy very quick. Am I missing something? Or is this really just a made up example and in real-life we’d never do something like this. If I was doing this pattern in real code, I don’t think I’d use the data class / interface this way. I’d be able to get the classes to evaluate down to a value on their own, but then I wouldn’t need to worry about downcasting then (which defeats the point of the exercise)jaspersmit
05/16/2019, 1:40 PM