oday
01/31/2018, 12:09 PMlinearLayoutManager = new LinearLayoutManager(context) {
@Override
public boolean canScrollVertically() {
return false;
}
};
Ruckus
01/31/2018, 11:24 PMval description = descriptionTextView.text.toString().takeUnless { it.isBlank() } ?: "A DefaultString"
poohbar
02/01/2018, 4:34 PMval (one, two, three) = listOf(0, 0, 0)
😄kevinmost
02/01/2018, 5:23 PMval (one, two, three) = IntArray(3) { 0 }
oday
02/01/2018, 7:54 PMSlackbot
02/01/2018, 8:59 PModay
02/02/2018, 10:47 AMval statusMap = mutableMapOf(
noreply to 0, contacted to 0, finished to 0,
negotiating to 0, sold to 0, notContacted to 0
)
searchResults.forEach {
if (statusMap.containsKey(it.state)) {
statusMap[it.state] = statusMap.getValue(it.state) + 1
}
}
Athul Antony
02/03/2018, 12:50 PMEleos
02/04/2018, 11:35 AMkef
02/05/2018, 7:47 PMval a = listOf(Pair("a", 1), Pair("a", 2), Pair("b", 1))
into:
[(a, 3), (b, 1)]
So, just group by key and sum values
Best I can do is:
a.groupBy ({ it.first}, {it.second} ).map{(key, value) -> key to value.sum()}
but there must be better waykef
02/05/2018, 8:31 PMa.groupByKey{(x,y) -> x+y}
where x
and y
are values from pairs with identical keys,
but I understand there is no such method in std libraryhho
02/06/2018, 1:40 PMobject.wait()
and object.notify()
.
What's the best way to convert this to Kotlin?
The converter in IntelliJ replaces Object
with Any?
, but wait()
and notify()
are of course not defined on Any
.Bob
02/06/2018, 5:29 PMit
single lambda parameter paradigm working in the context of what I guess would be an anonymous lambda? For a trivial example:
kotlin
val test: Pair<String, (String) -> Boolean> = "length is 6" to { input -> input.length == 6 }
Is there a way I can get the implicit it
parameter in there?karelpeeters
02/06/2018, 6:31 PMcedric
02/07/2018, 7:45 AM?.let
, not .let
chb0kotlin
02/09/2018, 6:14 AM@Entity
data class Form(@Id @GeneratedValue override var id: Long? = null,
override var date: Date? = null,
override var name:String? = null) : Post
Then, it's good. Except, I now have settersscap
02/09/2018, 7:05 AMclass Foo internal constructor() {
var bar: Int = 0
private set
var fuz: String = ""
private set
constructor(a: Int, b: String) : this(){
this.bar = a
this.fuz = b
}
}
var foo = Foo(9,"hello world")
juhanla
02/09/2018, 11:18 AMShawn
02/10/2018, 4:07 AMKCallable
forbloder
02/10/2018, 4:07 AMclass ExampleClass(private val targetClass: KClass<*>, private val solution: KCallable<*>) {
private val studentMethod by lazy {
var methodFinding: KCallable<*>? = null
for (m: KCallable<*> in targetClass.declaredMembers) {
if (m.name == solution.name && (methodFinding == null || validateParameterTypes(m))) {
methodFinding = m
}
}
methodFinding
}
private fun validateParameterTypes(m: KCallable<*>): Boolean { ... }
}
rellenberger
02/12/2018, 7:08 PMKenneth
02/12/2018, 10:32 PM@Configuration
class MetricsConfig {
@Bean
fun commonTags(): MeterRegistryCustomizer<MeterRegistry> = { registry ->
registry.config().commonTags("kenneth", "kenneth2")
}
}
Gives:
Inferred type is a function type, but a non-function type MeterRegistryCustomizer<MeterRegistry> was expected. Use either '= ...' or '{ ... }', but not both
adalbert
02/13/2018, 6:05 PMoverride fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as Model
if (name != other.name) return false
if (lastName != other.lastName) return false
if (password != other.password) return false
return true
}
We can change it to this
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as Model
return name == other.name
&& lastName == other.lastName
&& password == other.password
}
And my question is if this possible to get rid of all ifs? Why, why not?
override fun equals(other: Any?): Boolean {
return this === other
|| javaClass == other.javaClass
&& name == other.name
&& lastName == other.lastName
&& password == other.password
}
If this post is too long i will try to shrink itscap
02/13/2018, 9:07 PMchb0kotlin
02/14/2018, 6:59 AMinterface AclClassRepository : PagingAndSortingRepository<AclClass, Long>
@Component
class SecurityConfiguration(private val classRepo: AclClassRepository) : WebSecurityConfigurerAdapter() {
@PostConstruct
private fun init() {
val context = SecurityContextHolder.getContext()
context.authentication = UsernamePasswordAuthenticationToken("system", "system",
createAuthorityList("ROLE_ADMIN"))
val all = classRepo.findAll()
val reflections = Reflections(this.javaClass.`package`.name)
val entities = all - reflections.getTypesAnnotatedWith(Entity::class.java)
// Error:(64, 42) Kotlin: Type parameter bound for S in fun <S : AclClass!> save(p0: S): S
is not satisfied: inferred type Any! is not a subtype of AclClass!
entities.forEach { classRepo.save(it) }
//Error:(65, 23) Kotlin: Type parameter bound for S in fun <S : AclClass!> saveAll(p0: (Mutable)Iterable<S!>): (Mutable)Iterable<S!>
is not satisfied: inferred type Any! is not a subtype of AclClass!
classRepo.saveAll(entities)
SecurityContextHolder.clearContext()
}
}
karelpeeters
02/15/2018, 8:35 AMctrl+Q
on the parameters to double-check their types?karelpeeters
02/15/2018, 8:35 AMfun turnOn() { state = true }
right, assignments aren't expressions.laht
02/15/2018, 12:19 PMVesko Vujovic
02/15/2018, 2:52 PMedhu
02/15/2018, 5:32 PMfun main()...
function that I execute. when I execute the main function, the program runs, but I know there are exceptions being thrown by my code but none get outputted to my console. How can I setup logging so that I can see the logs in the console?edhu
02/15/2018, 5:32 PMfun main()...
function that I execute. when I execute the main function, the program runs, but I know there are exceptions being thrown by my code but none get outputted to my console. How can I setup logging so that I can see the logs in the console?fred.deschenes
02/15/2018, 5:53 PMedhu
02/15/2018, 6:02 PMio.github.microutils:kotlin-logging:1.4.9
if i log statements in my project, it works. but the exceptions being thrown from a Jar dependency that i call do not get shown in the consoleProcess finished with exit code 0
fred.deschenes
02/15/2018, 6:22 PMedhu
02/15/2018, 6:23 PMcompile 'org.slf4j:slf4j-api:1.7.10'
fred.deschenes
02/15/2018, 6:25 PMedhu
02/15/2018, 6:26 PMfred.deschenes
02/15/2018, 6:30 PMedhu
02/15/2018, 6:30 PMfred.deschenes
02/15/2018, 6:31 PMlogger.error(...)
with your caught exceptionedhu
02/15/2018, 6:35 PMfred.deschenes
02/15/2018, 6:39 PMedhu
02/15/2018, 6:42 PMfred.deschenes
02/15/2018, 6:46 PMdave08
02/16/2018, 3:47 AMrunBlocking
and await
or join
. CommonPool is the default thread pool dispatcher in coroutines... you need to wait for the result to come back from the thread...edhu
02/16/2018, 10:20 AM