janvladimirmostert
11/20/2018, 8:58 PMinterface JsonProvider {
fun <T> fromJson(input: String): T
fun <T> fromJsonList(input: String): List<T>
}
Gson for example now requires the class type to be passed in:
class Blah : JsonProvider {
val gson = com.google.gson.Gson()
override fun <T> fromJson(input: String): T {
return gson.fromJson(input, T::class.java)
}
unless that T
is reified and fromJson / fromJsonList are inlined, IntelliJ complains and reifying that T inside the interface doesn't seem to be supported.Uzi Landsmann
11/20/2018, 11:20 PMedwardwongtl
11/21/2018, 4:25 AMenum class GeneralModifier {
Less, Normal
}
data class Latte(
val ice: GeneralModifier = GeneralModifier.Normal,
val milk: GeneralModifier = GeneralModifier.Normal
) : Coffee()
And the selection input is Pair<String, Enum<GeneralModifier>>
, where the first one is the field name, e.g. “ice”
So I do
tem.copy(
ice = if (field == "ice") GeneralModifier.values().first { it == option } else item.ice,
milk = if (field == "milk") GeneralModifier.values().first { it == option } else item.milk
)
Is there a easier way to do the copy
?Bernhard
11/21/2018, 10:16 AMzokipirlo
11/21/2018, 11:28 AMsindrenm
11/21/2018, 12:00 PM@ExperimentalContracts
annotation absolutely everywhere. Thanks! :D
Not entirely sure where to ask for this. If it's suitable for another channel, I'd be happy to move the question over there.gsala
11/21/2018, 1:35 PMenum class Potato(val a : Int) {
Potato(3);
}
This is possible in Java but it seems like it's not allowed in Kotlin?Adrian Wawrzak
11/21/2018, 2:27 PMsindrenm
11/21/2018, 2:56 PMkotlin.RuntimeException
is actually just a typealias for java.lang.RuntimeException
). And all of Kotlin's own exceptions will ultimately inherit from kotlin.Throwable
, whereas Java's exceptions will inherit from java.lang.Throwable
). But does that mean that catching kotlin.Throwable
only won't actually catch e.g. `java.lang.RuntimeException`s?user
11/21/2018, 3:22 PMAndrew Gazelka
11/21/2018, 3:31 PMisEmpty
be a function? Also wouldn't the value stored in isEmpty
never be referenced?Andrew Gazelka
11/21/2018, 3:42 PMreik.schatz
11/21/2018, 4:03 PMigor.wojda
11/21/2018, 4:33 PMmaster
branch here https://github.com/JetBrains/kotlin/commits/master. Am I looking at incorrect branch 🤔Slackbot
11/21/2018, 6:52 PMAndrew Gazelka
11/21/2018, 7:28 PMsequence{}
... except I wouldn't return anything and just execute... (so if I used 'yield' I would have to return meaningless values). Is there a better way to implement this?ienoobong
11/22/2018, 6:28 AMkschlesselmann
11/22/2018, 7:08 AMimport org.springframework.boot.ApplicationRunner
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean
import org.springframework.data.annotation.Transient
import org.springframework.data.mongodb.core.mapping.Field
import org.springframework.data.repository.reactive.ReactiveCrudRepository
import org.springframework.stereotype.Repository
import reactor.core.publisher.Flux
import java.util.*
class Test(
list: List<String>,
val id: UUID = UUID.randomUUID()
) {
@Field("list")
private val _mutableList: MutableList<String> = list.toMutableList()
val list: List<String>
@Transient get() = _mutableList
}
@Repository
interface TestRepository : ReactiveCrudRepository<Test, UUID>
@SpringBootApplication
class DemoMongoMappingApplication {
@Bean
fun runner(testRepository: TestRepository) = ApplicationRunner {_ ->
Flux.just("a", "b", "c")
.map { Test(listOf(it)) }
.collectList()
.flatMapMany { testRepository.saveAll(it) }
.flatMap { testRepository.findById(it.id) }
.subscribe { println("Found $it.id") }
}
}
fun main(args: Array<String>) {
runApplication<DemoMongoMappingApplication>(*args)
}
Sadly this fails during load of my entities with org.springframework.data.mapping.MappingException: No property list found on entity class com.example.demomongomapping.Test to bind constructor parameter to!
. The problem seems to be with the backing property _list
. Any suggestions how you solve those issues?liusbl
11/22/2018, 12:04 PMfrellan
11/22/2018, 12:30 PMDB
class. How can I do that in kotlin?kschlesselmann
11/22/2018, 1:11 PMserebit
11/22/2018, 3:10 PMserebit
11/22/2018, 4:14 PMcoder82
11/22/2018, 4:52 PMcoder82
11/22/2018, 4:55 PMjmfayard
11/22/2018, 5:23 PM$ ./staticAnalysis android.app.Activity
android.app.Activity
\-- FragmentActivity
\-- AppCompatActivity
\-- MyActivity1
\-- MyActivity2
Does that exist?igor.wojda
11/22/2018, 5:27 PMKoin
or Kodein
and why?Shawn
11/22/2018, 7:49 PMreified
vs no type param, (thanks for clarifying @halley))? the compiler complains about a platform declaration clash, which I suppose makes sense since there’s no real overloading happening there, but since the second method has to be inline
anyhow, could the compiler not figure out what you mean at compile time and inline the appropriate method to avoid the signature clash?dewildte
11/22/2018, 8:17 PMSlackbot
11/22/2018, 11:15 PMSlackbot
11/22/2018, 11:15 PMShawn
11/22/2018, 11:18 PM