Hexa
07/17/2018, 6:14 PMimport com.fasterxml.jackson.databind.ObjectMapper
fun main ( args : Array < String > ) {
val mapper = ObjectMapper()
val jsonResult = mapper.writerWithDefaultPrettyPrinter()
.writeValueAsString(someString)
System.out.println("blank: ${jsonResult.isBlank()}")
System.out.println("isEmpty: ${jsonResult.isEmpty()}")
System.out.println("{}: ${jsonResult.contentEquals("{}")}")
}
jsonResult
returns {}
in my logs which means its a an empty json. How do I check if jsonResult is equals to {}
(or empty). All of my println returns false
, so isEmpty
and isBlank
dont work.elect
07/18/2018, 8:45 AMAyden
07/18/2018, 10:02 AMAyden
07/18/2018, 10:36 AMinstanceof
, but I don't think it can be use like typeof
Hexa
07/18/2018, 11:46 AMaerb
07/18/2018, 6:50 PMFiles
implementation. Behaviour can stay the same, but accept an option to change behaviour.Jonathan Walsh
07/19/2018, 12:38 AMsequenceOf(1L, 2L, 3L).map { it + 1L }.forEach { println(it) }
Jiddles
07/19/2018, 2:03 PM// The below code results in a compilation error
data class ViewModel(
var lineSpeed: Int? = null
)
val viewModel = ViewModel()
if(viewModel.lineSpeed != null && viewModel?.lineSpeed > 0 ) {}
//Error : Smart cast to 'Int' is impossible, because 'viewModel.lineSpeed' is a mutable property that could have been changed by this time
arekolek
07/19/2018, 3:54 PMfun <K, V> Map<K, V?>.filterValuesNotNull() = filterValues { it != null } as Map<K, V>
? I'm not sure I would even define it at allredrield
07/19/2018, 11:07 PMJDK_16="C:\\Program Files\\Java\\jdk1.6.0_45"
JDK_17="C:\\Program Files\\Java\\jdk1.7.0_80"
JAVA_HOME="C:\\Program Files\\Java\\jdk1.8.0_172"
JDK_9="C:\\Program Files\\Java\\jdk-9.0.4"
but when I try to import gradle project in intellij it says that JDK_16 isn't a valid jdk home pathredrield
07/19/2018, 11:13 PMkango_v
07/20/2018, 12:55 PMkango_v
07/20/2018, 12:56 PMSlackbot
07/20/2018, 3:13 PMdsavvinov
07/20/2018, 4:31 PMSlackbot
07/20/2018, 6:26 PMSlackbot
07/20/2018, 7:38 PMskennedy
07/20/2018, 7:47 PMname
on B
gets a String
instead of String?
?
open class A(val name: String?)
class B(name: String) : A(name)
fun findName(b: B): String = b.name // errors because `b.name` is `String?`
Diefferson
07/21/2018, 6:14 PMUdit003
07/22/2018, 11:20 AMDennis Cornwell
07/22/2018, 5:40 PMMarcus Fihlon
07/23/2018, 3:05 PMSlackbot
07/23/2018, 5:15 PMuser
07/24/2018, 7:11 AMvpriscan
07/24/2018, 9:03 AMJamie Lynch
07/24/2018, 1:08 PMwarriorprincess
07/24/2018, 3:25 PMfun findCombs(res: List<String>, digis: List<Int>) : List<String> = if (digitss.isEmpty()) res
else for (letter in map[digis[0]]) findCombs(res + letter, digis.subList(1, digis.lastIndex))
janos
07/24/2018, 5:51 PMJanar
07/24/2018, 5:52 PMelect
07/24/2018, 5:55 PMif (io.imeSetInputScreenPosFn != null && (g.platformImePos - g.osImePosSet).lengthSqr > 0.0001f)
io.imeSetInputScreenPosFn(g.platformImePos.x.i, g.platformImePos.y.i) // error, Reference has a nullable type
where val imeSetInputScreenPosFn: ((x: Int, y: Int) -> Unit)?
But I should profit from the smart cast from the if
that ensures it's not nullelect
07/24/2018, 5:55 PMif (io.imeSetInputScreenPosFn != null && (g.platformImePos - g.osImePosSet).lengthSqr > 0.0001f)
io.imeSetInputScreenPosFn(g.platformImePos.x.i, g.platformImePos.y.i) // error, Reference has a nullable type
where val imeSetInputScreenPosFn: ((x: Int, y: Int) -> Unit)?
But I should profit from the smart cast from the if
that ensures it's not nullrook
07/24/2018, 6:04 PMimeSetInputScreenPosFn
is a var
, so the compiler (correctly) thinks that it can become null if there’s an asynchronous operation that changes it.elect
07/24/2018, 6:04 PMval
, that's the problem..rook
07/24/2018, 6:06 PMelect
07/24/2018, 6:06 PMrook
07/24/2018, 6:08 PMio
nullable?elect
07/24/2018, 6:08 PMkarelpeeters
07/24/2018, 6:52 PMio.imeSetInputScreenPosFn
isn't null, where both io
and imeSetInputScreenPosFn
are `val`s?rook
07/24/2018, 7:52 PMkarelpeeters
07/24/2018, 8:26 PMclass Test(val str: String?)
val test = Test("hey")
test.str.toUpperCase() //not allowed
if (test.str != null)
test.str.toUpperCase() //allowed
elect
07/24/2018, 8:30 PMio
is a var
, but is not nullablekarelpeeters
07/24/2018, 8:34 PMio
reference could have changed between the check and the indexing.rook
07/24/2018, 9:29 PMclass SomeClass(val str: String?)
var test = SomeClass("yo")
fun main() {
test.str.toUpperCase() //Only safe calls etc. (use ?.)
if(test.str != null) {
test.str.toUpperCase() //Smart cast to String is impossible, because 'test.str' is a complex expression
}
}
karelpeeters
07/24/2018, 9:30 PMvar
. Make it a val
and it'll work.rook
07/24/2018, 9:31 PMkarelpeeters
07/24/2018, 9:32 PMelect
07/25/2018, 7:26 AMrook
07/25/2018, 3:35 PM