iex
05/03/2020, 12:49 PMval digest = MessageDigest.getInstance("SHA-256")
digest.update("bar".toByteArray())
val str = digest.digest().toString(UTF_8)
val digest2 = MessageDigest.getInstance("SHA-256")
digest2.update("sldkjfskfjs".toByteArray())
val str2 = digest2.digest().toString(UTF_8)
// str == str2 --> true!
Ryan
05/03/2020, 3:52 PMOfir Bar
05/03/2020, 5:56 PMVenkat
05/03/2020, 11:59 PMHadi Lashkari
05/04/2020, 10:01 AMPair(a,b) as? Pair<String, Boolean>
where a
or b
can be null, there is a Java warning that says Unchecked cast: Pair<String?, Boolean?> to Pair<String, Boolean>
. By supporting more strong typing system which supports generics type checking, we can make sure we're developing less buggy programs. I want to know is it possible to do so? For instance, why we cannot hold type info in the KClass in the runtime to check these kind of stuff? Thank you.Chilli
05/04/2020, 10:09 PMnatpryce
05/04/2020, 11:58 PMnwillc
05/05/2020, 12:27 AMJukka Siivonen
05/05/2020, 8:47 AMVladimirR
05/05/2020, 11:04 AMchristophsturm
05/05/2020, 4:35 PMAlex Kuznetsov
05/05/2020, 6:33 PMvar
as a read-only property. I need something like the following:
class Something(...) {
var counter_ = 0
fun doSomething() {
(snip)
counter_++
(snip)
}
val counter: Int get() = counter
Is there a better way?Sami Eljabali
05/05/2020, 7:52 PMrobstoll
05/05/2020, 8:23 PMtargetCompatiblity
in my build.gradle to be 8 but do not define kotlinOptions.jvmTarget
to be 1.8, so it should be 1.6 per default, what is the compiler supposed to generate?
I am asking because I came across java.util.function.Consumer
in the resulting byte code and this one was introduced in 1.8Regan Russell
05/06/2020, 3:26 AMfun performRequest<T>(request: ApiMessage<T>)
At a guess..??
Mustafa
05/06/2020, 10:31 AMgalex
05/06/2020, 10:38 AMguard
in Swift? The best we found for now is to implement a few functions of that sort:
fun <A : Any, B : Any> guard(a: A?, b: B?, block: (A, B) -> Unit): Boolean {
return if (a != null && b != null ) {
block(a, b)
true
} else {
false
}
}
This allows us to run code on a few different types and check that the block ran to have an else
part.
What do you think? It there something better out there? I checked Contracts but you can’t imply a list doesn’t contain a null
item, too bad.LastExceed
05/06/2020, 12:54 PMfor (x in y)
or do i have to remove them manually ?iex
05/06/2020, 3:29 PMinterface Preferences {
// ...
fun <T> putObject(key: PreferencesKey, model: T?)
fun <T> getObject(key: PreferencesKey, clazz: Class<T>): T?
}
Force returning a specific object, for unit testing
class PreferencesReturningObject<T>(val obj: T): Preferences {
override fun <T> putObject(key: PreferencesKey, model: T?) {}
override fun <T> getObject(key: PreferencesKey, clazz: Class<T>): T? = obj
}
How can I write this? (Without using Mockito or similar)
Edit: It's "fixed" by writing obj as T
(the class type parameter actually doesn't make sense, it can be just Any
) but wonder if there's a better wayAnaniya
05/06/2020, 5:43 PMcab
05/06/2020, 8:10 PMOfir Bar
05/07/2020, 2:32 PMPrimitives.kt
file,
Inside the Int primitive, there are methods to convert the Int to other primitives but I don't see any implementation.
I can't figure out how this conversion works.
What am I missing?Ofir Bar
05/07/2020, 2:33 PMiex
05/07/2020, 3:05 PMtaer
05/07/2020, 3:29 PMJanelle Fullen
05/07/2020, 5:31 PMYevhenii Nadtochii
05/07/2020, 10:36 PMoperator fun getValue(thisRef: Any, property: KProperty<*>): Any = properties[property.name]
?: throw IllegalStateException("Property ${property.name} hasn't been initialized!")
operator fun setValue(thisRef: Any, property: KProperty<*>, value: Any) {
properties[property.name] = value
listeners[property.name]?.invoke(value.toString())
}
Venkat
05/07/2020, 11:06 PMfunc*()
call returns a valid string and it's gets appended to the mutable string variable returnString
. As far as I know, FP functions should not use any mutable values. So how would I replace those string appending lines?
private fun stringifyValue(): String {
var returnString = String()
returnString = returnString.plus("=")
returnString = returnString.plus(func1())
returnString = returnString.plus("+/")
returnString = returnString.plus(func2())
returnString = returnString.plus("@")
returnString = returnString.plus(func3())
returnString = returnString.plus("#")
returnString = returnString.plus(func4())
returnString = returnString.plus("%")
returnString = returnString.plus(func5())
returnString = returnString.plus("^")
return returnString
}
Alex Wilson
05/08/2020, 12:16 AMfun main() {
val list = """
a,234,97654/
b,23,ABC,
b,44235,203
a,234,97654/
b,23,ABC
b,44235,203
49,234
39,9291
""".trimIndent().split("\n")
var total = mutableListOf<String>()
for ((index, value) in list.withIndex()){
var sb = StringBuilder()
var nextIndex = index
if(value.startsWith("a") && value.endsWith("/")) {
sb.append(value)
while(list[nextIndex + 1].startsWith("b")) {
sb.append(list[nextIndex + 1])
nextIndex++
}
total.add(sb.toString())
}
}
}
frogger
05/08/2020, 9:31 AM