Marcus Brito
10/20/2021, 8:34 PMdmcg
10/20/2021, 8:34 PMdmcg
10/20/2021, 8:35 PMMarcus Brito
10/20/2021, 8:35 PMMarcus Brito
10/20/2021, 8:38 PMdmcg
10/21/2021, 7:53 AMPiotr Krzemiński
11/05/2021, 8:43 AMstdlib
explicitly, it's added by default. I wanted to report an errata via O'reilly, but formally it's not an error, just an idea for simplification showing that onboarding Kotlin is even simpler. Is this channel a good place for such suggestions?Piotr Krzemiński
11/08/2021, 1:31 PMequals
and hashCode
, and it's actually great point - I've never looked at it this way, maybe because I create deeply immutable data classes (unless I refactor some JavaBeans-style code, I leave `var`s temporarily)
IMO IntelliJ should add a warning/inspection, like it's done for e.g. using Optional
for class fields. The goal still being able to create a concise, kotlinic version of a JavaBean, but not pretending that it's fine 🙂 .WDYT?Philipp Mayer
03/28/2022, 7:01 PMPhilipp Mayer
03/29/2022, 9:00 AMWesley Hartford
05/05/2022, 7:43 PMMap.computeIfAbsent()
function documentation includes:
However, when calling this function from Kotlin code, the mapping function has a signatureCopy codeIf the mapping function returns {@code null}, no mapping is recorded.
(K) -> V
, meaning that the passed in function cannot return null
. Is there any way to use computeIfAbsent
from kotlin passing a function which may return null
?Kev
11/17/2023, 6:05 AMkotlin.collections.List
interface. Does anyone know where I can find the implementation of this interface?natpryce
11/17/2023, 12:00 PMnatpryce
11/17/2023, 12:01 PMJose Ramon (JR)
12/02/2023, 11:35 PMdmcg
12/08/2023, 8:15 PMdmcg
12/08/2023, 8:17 PMDarryl Miles
12/16/2023, 4:55 PMDarryl Miles
12/16/2023, 4:57 PMkotlin('plugin.jpa')
already provides for JPADarryl Miles
12/16/2023, 4:58 PMDarryl Miles
12/17/2023, 11:33 AMlateinit
to confirm they have an expected injection annotation on the field, and maybe warn if the field is left public.
Maybe there is also the ability to put the plugin in debug build mode and it will insert implicit call to assertion check of all lateinit
at runtime maybe at the end of all constructors such as constructor() { myBusinessLogicMethodCall(); injectedKotlinLateInitInjectionChecker() }
and a method inserted like private fun injectedKotlinLateInitInjectionChecker() { assert((FieldType?)fieldName != null) {"injected Kotlin lateinit usage check failed on field: fieldName"} }
Darryl Miles
03/03/2024, 5:26 AMval kclass = MyEntity::class
val randomMember = kclass.members.findLast { it.name == "randomProperty" } // KCallable<*>
val kmutable = if(randomMember is KMutableProperty) randomMember as KMutableProperty else null // KMutableProperty is the real type
val javaField = kmutable?.annotations // this is the only non-empty annotations field/member/method/property that exists around "randomProperty"
Darryl Miles
03/03/2024, 5:27 AMDarryl Miles
03/03/2024, 5:29 AM@jakarta.validation.constraints.Size(max = 123) open var randomProperty: String? = null
Darryl Miles
05/16/2024, 7:37 PMprivate
keyword on a method, because it seems Kotlin will make it static
or final
and use of private open fun methodName()
is invalid use of open
keyword.
However it seems it is not advised to final
the method due to the proxy nature of EJB application server, because many facets are injected/provided so the container needs to be free to perform interception/injection of anything it sees fit to manage EE requirements.
Is there a solution, is this a bug with kotlin("plugin.allopen")
not understanding the full requirements ? ThanksDarryl Miles
05/16/2024, 7:40 PM/** private **/ fun methodName()
to at least document the programmers intention, even if the language forcing something else.natpryce
05/17/2024, 10:54 AMWesley Hartford
06/12/2024, 4:08 PM@Nonnull
. Kotlin knows that my implementing function should have non-null types for those parameters. The only problem is, the Java code which calls the interface passes null
for these @Nonnull
annotated parameters. Kotlin, of course, throws an exception when null
is passed to a non-null type. I'd like to change the signature of my function to have nullable types, but then Kotlin tells me that its no longer implementing the function it should be. Is there any way to tell Kotlin to ignore the annotations on that method or the specific parameters? I've filed a bug report with the maintainer of the interface, but I'd like to move forward before the fix is released.Darryl Miles
12/02/2024, 12:16 PMMyType[].class
in kotlin ? MyType::class.java.arrayType()
does not seem to be it, I get [UNRESOLVED_REFERENCE] back.
Code snippet looks like:
class MyType<T> {
val targetClass: Class<T>
val isArrayType: Boolean
constructor(targetClass: Class<T>, isArrayType: Boolean = false) {
this.targetClass = targetClass
this.isArrayType = isArrayType
}
fun toTypeForJackson(): Class<*> {
return if(isArrayType) targetClass.arrayType() else targetClass /// <<< ERROR HERE
// tried also: targetClass.arrayType()::class.java
}
}
Java code that compiles:
public class MyUtil {
public static <T> Class<?> foo(Class<T> targetClass, boolean isArrayType) {
if(isArrayType)
return targetClass.arrayType();
else
return targetClass;
}
}
Just testing it works as expected, maybe I make a Java library project with this util method to resolve ?
UPDATE: Doh! so Class#arrayType() came with JDK12 and project targets JDK11 as it is a library project, while runtime testing is JDK21. Solution java.lang.reflect.Array.newInstance(targetClass, 0)::class.java
Svatopluk Šimara
04/06/2025, 5:17 AM"Hello, %s".formatted(name)
-> "Hello, %s".format(name)
I'm not looking for regexs, I tried Kotlin complier API - with some chatgpt promps, but I keep having troubles converting even such simple code - I can parse it, find the relevent method, but not replace it 😕
Basically I'm looking for something like https://errorprone.info/docs/refaster - a tool that allows automated refactorings OR a piece of code where is the Kotlin compiler setup correctly 🙂
My trouble isn't just formatted
- I have 500K LOC project, and I want to resolve all problems at once