felipepedroso
05/29/2019, 10:58 AMMahdi Javaheri
05/29/2019, 12:27 PM@JvmStatic
?
without need to annotating individual functionsthana
05/29/2019, 4:24 PMsynchronized
for common
but not for js
and jvm
- which in fact are the both platforms i target. is there a way to use it in common
without the deprecation warnuing?Kotlin-Jobs.com
05/29/2019, 6:00 PMDan T
05/29/2019, 8:25 PMKroppeb
05/29/2019, 10:57 PMinline fun StringReader.tryTo(block: StringReader.TryTo.() -> Unit){
contract {
callsInPlace(block, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
}
try {
it.block()
} catch (e: Exception) {
it.reset()
}
}
And
override fun parse(reader: StringReader): String? {
reader.tryTo {
throw Exception("hi")
}
return null // Marked as unreachable code
}
On a inline lambda seems to not realise that an exception that is thrown in the lambda can be caught in the inlined function. This gets even worse when the return is not nullable and the user doesn't add a return as it is marked as unreachable and as a result at runtime the function will return null.Valentyn
05/30/2019, 12:59 AMmike_shysh
05/30/2019, 7:18 AMRohan Maity
05/30/2019, 9:49 AMRak
05/30/2019, 2:31 PMMarc Knaup
05/30/2019, 3:06 PM*
btw?
Could be something more comprehensible like this 🤔
ByteString.of(vararg buffer.toByteArray())
Kroppeb
05/30/2019, 8:10 PMas? TArgument
give an Unchecked cast
warningoscarg798
05/30/2019, 8:54 PMandre.ramaciotti
05/31/2019, 12:22 PMObjectMapper
). So I know that I need to pass the class as an argument. But then, I also need to specify the type T
when instantiating the generic base class. Is there a way of making the compiler infer any of the two?
data class ExamplePayload(val value: String, val otherValue: Int)
abstract class Worker<T : Any>(private val kclass: KClass<T>) {
private lateinit var objectMapper: ObjectMapper
fun handleMessage(message: String) {
val payload = objectMapper.readValue(message, kclass.java)
work(payload)
}
protected abstract fun work(payload: T)
}
// Here I need to specify ExamplePayload twice:
class ExampleWorker : Worker<ExamplePayload>(ExamplePayload::class) {
override fun work(payload: ExamplePayload) {
TODO("not implemented")
}
}
Kroppeb
05/31/2019, 3:34 PMQuy D X Nguyen
05/31/2019, 7:57 PMkarelpeeters
06/01/2019, 12:00 AMenighma
06/01/2019, 12:02 AMSOFe
06/01/2019, 7:13 AMthana
06/01/2019, 11:04 AMinit
block. in the end they wont be split this way.
you can use by lazy{}
with `val`sAndrew Gazelka
06/02/2019, 1:54 AMAndrew Gazelka
06/02/2019, 2:13 AMmain
functions in different files but not the same actual function nameAndrew Gazelka
06/02/2019, 2:18 AMiterator()
method?Andrew Gazelka
06/02/2019, 5:33 AMcypher121
06/02/2019, 8:33 AMfun <E : Enum<E>> foo(clazz: Class<E>): Value<E> = TODO()
fun <T> bar(clazz: Class<T>) {
if (Enum::class.java.isAssignableFrom(clazz)) {
foo(clazz) //fails since T is not Enum<T>
}
}
how do I call foo here? I tried foo<Enum<*>>(clazz as Class<Enum<*>>)
but it fails since * is also not Enum<*> and it just keeps going recursively. In java I'd just use a raw Enum type, but I can't do that hereFelix Novovic
06/02/2019, 12:34 PMval now = DateTime(DateTimeZone.UTC)
val inTwoHours = now + Duration.standardHours(2)
println(inTwoHours.millis)
Very simple, I just want to copy the time in millis and put it in another file I'm messing around with. However, when I run the scratch file it evaluates perfectly fine but shows the output to the right of the println
statement which I cannot copy or select. I really like the ideas of scratch files and I believe it to be an invaluable tool when doing some manual testing and experimentation but I cannot seem to find how to just print it to the normal console. Anyone has any clue? (Using IntelliJ Ultimate)uli
06/02/2019, 1:06 PMtypealias Factory<T> = () -> T
private fun Bundle.getViewModelFactory(): (() -> VIEWMODEL)? {
val serializable = getSerializable(ARG_VIEWMODEL_FACTORY)
return serializable as? Factory<VIEWMODEL>
}
Shouldn't as?
take care of this?AnnoymousGiraf
06/02/2019, 11:44 PMthana
06/03/2019, 8:59 AMdata classes
are not allowed to have non-properties in their primary constructors. otoh this means data classes cannot inherit from classes that require arguments in their own primary constructor. is there a way to overcome this issue? is this really intended? why?tseisel
06/03/2019, 9:36 AMcrossinline
keyword required ? Is it a real language feature, or rather a technical limitation of the compiler ?tseisel
06/03/2019, 9:36 AMcrossinline
keyword required ? Is it a real language feature, or rather a technical limitation of the compiler ?gildor
06/03/2019, 9:38 AMDico
06/03/2019, 10:03 AM