Andrey Logoshko
02/11/2021, 1:27 PMdf
02/11/2021, 2:45 PM1L.rem(200) == 0
compiles without errors while it should fail because rem returns Long. Using Kotlin playground the code does not compile as expected. Any idea whats going on? org.jetbrains.kotlin:kotlin-stdlib-jdk8:jar:1.4.30:compile
Brian Fox
02/11/2021, 2:46 PMCdev
02/11/2021, 7:18 PMMarc Knaup
02/11/2021, 8:18 PM<in T>
as <out Any?>
?sbeve
02/11/2021, 9:13 PMconst val LOWER_CASE_LETTERS = "abcdefghijklmnopqrstuvwxyz"
const val UPPER_CASE_LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
fun rotateLetter(input: Char, rotations: Int): Char {
val isUpperCase = input in UPPER_CASE_LETTERS
val isLowerCase = input in LOWER_CASE_LETTERS
var variableRotations = rotations
var variableInput = input
while (variableRotations != 0) {
when {
isUpperCase -> {
if (variableInput.toInt() == 90) variableInput = 'A'
else variableInput += 1
}
isLowerCase -> {
if (variableInput.toInt() == 122) variableInput = 'a'
else variableInput += 1
}
else -> return input
}
variableRotations--
}
return variableInput
}
Patrick Ramsey
02/11/2021, 10:11 PMRobinnsson Cifuentes
02/12/2021, 12:44 AMRobinnsson Cifuentes
02/12/2021, 12:49 AMhellman
02/12/2021, 7:31 AModay
02/12/2021, 7:59 AMSudhir Singh Khanger
02/12/2021, 8:05 AMval loginPage = loginPageResponseBody.loginPage
if (loginPage != null) {
loginPageData.postValue(loginPage)
}
If I am doing the null check then why does postValue
method complains about requiring Expected non-nullable value
. I don't get this error with loginPage.let { loginPageData.postValue(it) }
.Eugen Martynov
02/12/2021, 9:15 AMoperator fun <T> T.plus(list: List<T>): List<T> {
val result = list.toMutableList()
result.add(0, this)
return result
}
mzgreen
02/12/2021, 11:39 AMdmcg
02/12/2021, 12:15 PMFlorian
02/12/2021, 2:55 PMandylamax
02/12/2021, 3:44 PMPhilip Dukhov
02/12/2021, 3:58 PMdata class
to have non optional field, but to be able to initialize it with a nil, which will be replaced by a default value. Something like this:
data class Text(val text: String) {
constructor(textNullable: String?) : this(textNullable ?: "", nullable)
}
It works well on native, but on JVM I got following error:
Platform declaration clash: The following declarations have the same JVM signature (<init>(Ljava/lang/String;)V):
constructor Text(text: String) defined in ...
constructor Text(textNullable: String?) defined in ...
Any way I can bypass it? I think I could replace data class
with class
to remove the default constructor, but in this case I’ll lose other data class advantages, like copy(...)
agnaldo4j
02/12/2021, 5:28 PMRob Elliot
02/12/2021, 6:12 PMsbeve
02/12/2021, 8:25 PMfun rotateLetter(input: Char, rotations: Int): Char {
var variableInput = input.toInt()
val isUpperCase = variableInput in 65..90
val isLowerCase = variableInput in 97..112
when {
isUpperCase -> {
if (variableInput + rotations <= 90) variableInput += rotations
else variableInput = 64 + (variableInput + rotations - 90)
}
isLowerCase -> {
if (variableInput + rotations <= 122) variableInput += rotations
else variableInput = 96 + (variableInput + rotations - 122)
}
else -> return input
}
return variableInput.toChar()
}
Vampire
02/13/2021, 3:27 AMjavax.xml.xpath.XPathFactory.newInstance().newXPath().compile("/").evaluateExpression(null)
give
error: unresolved reference: evaluateExpression
javax.xml.xpath.XPathFactory.newInstance().newXPath().compile("/").evaluateExpression(null)
^
when compiling the Kotlin code using Java 11?
The IDE has no problem, but if you compile it in a file or execute it in a REPL it says unresolved reference.
The method was added in Java 9Animesh Sahu
02/14/2021, 5:58 AMfun test(a: () -> Unit) { println("A") }
fun test(a: suspend () -> Unit) { println("B") }
suspend fun main() {
test {}
}
According to the language i.e. if kotlin - allow suspend lambda whereas call from non-kotlin like java/js - allow normal lambda 👀mending3
02/14/2021, 12:53 PMThread()
vs Kotlin coroutines?azharkova
02/14/2021, 4:46 PMKirill Grouchnikov
02/14/2021, 5:54 PMorg.jetbrains.kotlinx:kotlinx-collections-immutable
is still only available on jcenter / bintray. What's the right place to file a bug to move it over to Maven Central or Jetbrains' own space?mending3
02/15/2021, 4:59 AMconfigure<SourceSetContainer> {
named("main") {
java.srcDir("src/main/kotlin")
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
spring_boot
@PostMapping("/my-endpoint")
fun createProject(@RequestParam request: Map<String, String>): ResponseEntity<Map<String, String>> {
val filePath = request["filepath"]
try {
val thread = thread {
try {
MyCustomClass(filePath)
} catch (e: Exception) {
when (e) {
is IOException, is SAXException, is ParserConfigurationException, is SQLException -> {
println(e)
}
else -> throw e
}
} // end of thread's try
}
thread.start()
return ResponseEntity.ok().body(
mapOf(
"message" to "success"
)
)
} catch (e: java.lang.Exception) {
return ResponseEntity.badRequest().body(
mapOf(
"message" to "error"
)
)
}
}
why does spring boot give me noclassdeffound on MyCustomClass
?Will Mwendwa
02/15/2021, 8:15 AMSwanand Keskar
02/15/2021, 1:41 PMNiklas Gürtler
02/15/2021, 1:57 PM@Suppress
in https://pl.kotl.in/xmmqu1Wqf ? It is unreachable but without it, I get a type mismatch error.Niklas Gürtler
02/15/2021, 1:57 PM@Suppress
in https://pl.kotl.in/xmmqu1Wqf ? It is unreachable but without it, I get a type mismatch error.Roukanken
02/15/2021, 2:12 PMfun <T> retry (run: () -> T) : T {
lateinit var lastError: Throwable
repeat(5) {
try {
return run()
} catch (currentError: Throwable) {
lastError = currentError
}
}
throw lastError
}
retry {
println("Hello, world!!!")
}
compiler doesn't scream at me for the lateinit, so I guess it can figure out that it will be set 😄Niklas Gürtler
02/15/2021, 2:15 PM