JasonB
07/18/2024, 8:19 PMuse
blocks: let's say I have a reader and a writer - if I nest the writer's use
inside of the reader's use
, and the reader is empty, will the writer's stream still be closed?Phil Richardson
07/26/2024, 7:26 PMgroovy.lang.Closure
is being accepted by Java to allow callback to the script. It does also allow processing of a javax.script.Invocable
.
I don't have much control over the SDK - but would certainly try and influence it with justification.
So if I wanted to say pass in an instance of a Kotlin function type, i.e. Lambda, anon-function or callable reference.
What would be the types that Java needs to handle? Are they different say between a Lambda and callable ref?
I know I could just specifically generate an Object that implements Callable, thus knowing the types by default, but that seems like forcing something over using the more natural - and readable - kotlin syntaxPHondogo
07/30/2024, 7:31 PMfor (v in UByte.MIN_VALUE..UByte.MAX_VALUE) {
println(v) // it is going after 255 and more. Why?
}
groostav
08/02/2024, 12:55 AMval left = listOf(
CoolRecord("name1", emptyList()),
CoolRecord("name2", emptyList()),
CoolRecord("name3", emptyList())
)
val right = listOf(
CoolRecord("name1", listOf(1.0, 2.0))
CoolRecord("name3", listOf(5.0, 6.0))
)
val result = reallySlickJoinFunction(left, right)
assertEquals(result, listOf(
CoolRecord("name1", listOf(1.0, 2.0)),
CoolRecord("name2", emptyList()),
CoolRecord("name3", listOf(5.0, 6.0))
))
anybody got some hints on how i can implement reallySlickJoinFunction
?groostav
08/02/2024, 12:57 AMright.single { record.name == target }
, because if target
comes from a loop thats a full cartesian product, and the data sets of left & right could be a thousand or so elements long
but they are ordered, so right[n]
must have a record in left
that occurs before right[n+1]
Holger Steinhauer [Mod]
08/08/2024, 10:20 AMAmir H. Ebrahimnezhad
08/21/2024, 3:11 PMgroostav
09/18/2024, 8:45 PMIndentedStringBUilder
anywhere? I feel like I've bumped into this need a couple times. I want a stringbuilder (or perhalps more simply an Appendable
) that will auto-insert a prefix for each newline.
something like
val builder = StringBuilder()
builder.appendLine("preamble {"}
val indented = builder.indent(indent = " ", indentCount = 2) // new reference but mutates same buffer as 'builder'
val multilineOutcodeString = someUserObject.toString()
indented.appendLine(multilineOutcodeString)
builder.appendLine("}")
print(builder.toString())
outputting
preamble {
SomeUserObjectThatOutputsManyLines:
SomeUserObjectExtraLine
line2
}
Amir H. Ebrahimnezhad
09/24/2024, 5:27 AMGilles Barbier
10/09/2024, 5:21 PMimport kotlinx.coroutines.channels.Channel
class Box<out M>(
// ...
)
interface Transport<S> {
// ...
}
interface Message {
// ...
}
fun <T : Message> test(
consumer: Transport<T>,
channel: Channel<Box<T>> = Channel()
): Channel<Box<T>> {
return channel
}
fun main() {
lateinit var consumer: Transport<out Message> // just to get the right type
var c = test(consumer)
}
Here the IDE (IntelliJ) does not see any issue. But If I ask IntelliJ to provide the type, I got:
var c: Channel<Box<Message>> = test(consumer)
But then IntelliJ itself tells me it's wrong and should be:
var c: Channel<out Box<Message>> = test(consumer)
At last, for both type, the can not provide it to the test
function - IntelliJ tells me it's not the right type
val c: Channel<out Box<Message>> = Channel()
test(consumer, c)
Any hint would be greatly appreciated!Varun Sethi
10/10/2024, 5:17 AMyoussef hachicha
11/07/2024, 7:59 AMmbonnin
11/07/2024, 5:06 PM// How do I do this in Kotlin?
interface Shape {
int area();
class Square implements Shape {
// private constructor here
private Square() {}
@Override public int area() {return 0;}
}
// more shapes...
/**
* static factory method
* Doesn't work on a Kotlin companion function because the Square constructor is private
*/
static Square square() {
return new Square();
}
}
Bilagi
11/10/2024, 8:24 AMAndrew O'Hara
11/11/2024, 9:07 PMclass BusinessLogic(
val getMessage: () -> String
)
I want to build a factory method that would let me override getMessage
with some static String.
fun createBusinessLogic(messageOverride: String? = null): BusinessLogic
I initially came up with this:
fun createBusinessLogic(
messageOverride: String? = null
) = BusinessLogic(
getMessage = if (messageOverride != null) {
{ messageOverride }
} else {
val random = Random(1337)
{ "Message ${random.nextInt()}" }
}
)
Which fails to compile, because the compiler thinks the () -> String
I'm trying to return is an argument to the Random
constructor. My workaround was to assign the lambda to a val
, and then return that on the next line.
fun createBusinessLogic(
messageOverride: String? = null
) = BusinessLogic(
getMessage = if (messageOverride != null) {
{ messageOverride }
} else {
val random = Random(1337)
val supplier = {
"Message ${random.nextInt()}"
}
supplier
}
)
But it's weird! And ugly! I feel like there should be a better way to do this, without resorting to something drastic like:
fun createBusinessLogic(
messageOverride: String? = null
) = if (messageOverride != null) {
BusinessLogic { messageOverride }
} else {
val random = Random(1337)
BusinessLogic { "Message ${random.nextInt()}"}
}
Which won't really fly in my real app, because the real-life BusinessLogic
has several more arguments that would be duplicated.Abhilash Mandaliya
11/13/2024, 10:47 AMserialVersionUID
for my classes implementing Serializable
? I found several plugin options or doing it manually but none of the plugins work with the latest version of IDEA? Isn't there any default support like Java?Stylianos Gakis
11/20/2024, 2:51 PMcopy()
function, only with the parameters that I need for each use case which will just create a new instance of the data class, just like the normal copy
function would.
Any reasons why I should not be doing that?Gilles Barbier
11/21/2024, 8:18 AMjuliocbcotta
12/04/2024, 12:28 PMNorbi
12/25/2024, 6:15 PMgroostav
01/19/2025, 7:33 AMScanner
, but it demands delimeters that I dont want to give it.
I was also hoping kotli might have a kind of reader + regex extension function, something like <http://java.io|java.io>.Reader.takeWhile(regex: Regex)
, but no luck there either.
What does a quintessential kotlin text tokenizer look like?Abhilash Mandaliya
01/24/2025, 6:40 AMsairaham@kotlin-dev-ThinkPad-P53:~/workspace/kotlin-dev-connect$ ./gradlew build -x test
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* Where:
Build file '/home/sairaham/workspace/kotlin-dev-connect/build.gradle.kts' line: 57
* What went wrong:
Class org.jetbrains.kotlin.cli.common.CompilerSystemProperties does not have member field 'org.jetbrains.kotlin.cli.common.CompilerSystemProperties COMPILE_INCREMENTAL_WITH_ARTIFACT_TRANSFORM'
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at <https://help.gradle.org>.
BUILD FAILED in 6s
5 actionable tasks: 1 executed, 4 up-to-date
I have no clue what is wrong here. Google search also didn't help with it. Any help is greatly appreciated 🙏Andrew O'Hara
02/03/2025, 5:07 PMEugen Mayer
02/07/2025, 9:00 AMSlackbot
02/10/2025, 10:40 AMCaleb B
02/24/2025, 3:58 PMMap<Class<T>, Supplier<T>>
, where T
is NOT a type parameter of the enclosing class but instead "pinning" the type of the supplier to the type of the class for runtime type validation? Instead of Map<Class<*>, Supplier<*>>
and having to suppress constant type coercion warningsRaj Paliwal
02/28/2025, 5:40 PMOTHER_REASON
• Description: ScreenOffCheckKill 26m3s4ms (26.33344%) threshold 2.0%
The issue occurs when a*fter screen turns off, app in background.*
The description in the exit logs suggests ScreenOffCheckKill, but I couldn’t find any official documentation explaining this behavior.
• What exactly does ScreenOffCheckKill
mean, and why does it happen?
• Is this a system-level restriction or a configurable setting?
• How can I prevent my app from getting killed due to this reason?
• Any pointers to official documentation or similar cases would be highly appreciated.
Thanks in advance for any insights!Amir H. Ebrahimnezhad
03/20/2025, 3:12 PMAmir H. Ebrahimnezhad
04/04/2025, 6:17 PMSebastian Schuberth
04/05/2025, 8:16 PMAutoClosables
) but for Kotlin code and use
?