我正在实现一个纯Kotlin库,我将在开源许可证下发布该库。在我的库中,假设有class A,我想在其中重写equals()。我使用了Android Studio的自动生成器来做这件事,但它包含了对javaClass的引用 override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as A
...
} 在纯Kotlin库中使用此参考资料安全吗?如果有人使用我的库来攻击J
我有一个包含以下模块的项目:
常见
普通js
公共jvm
后端
网站
我的想法是把我的共享( kotlin )代码(主要是模型)放在一起,它既可以使用kotlin驱动的后端,也可以使用最近推出的多平台支持在javascript驱动的webapp中使用。为此,我在Intellij中创建了一个新的多平台应用程序,并向其添加了后端和web模块。
公共模块中的示例类:
data class Show(
val id: Long,
val type: ShowType,
val title: String,
var description: S
在kotlin中,是否有现成的随机性来源?是否是标准java.util.Random、kotlin.math.random*或基本当前时间millis的一些实现,可以用来创建自己的随机数生成器?我什么都找不到。
如果不存在,那么在不设置您自己的平台相关实现的情况下,如何获得随机性的来源?这是我唯一需要的方法:
expect class Rng {
fun nextInt(): Int
}
我想让它成为不可知论者。
我试图在shared项目的模块中编写测试。在共享模块的build.gradle.kts文件中,我有以下内容:
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
//TOD
我试图为Kotlin多平台项目配置一个模板,在后端运行ktor,在前端配置react,使用jetbrains团队的Kotlin类型安全包装器。要在前端和后端之间共享代码,我需要使用gradle
build.gradle.kts
val kotlin_version: String by project
val ktor_version: String by project
val logback_version: String by project
val annotations_version: String by project
val kotlin_react_version: S
数据类在MPP项目中打印得很好。当我为我的类toString() KClass对象时,我得到:
class com.example.MySimpleClass (Kotlin reflection is not available)
我怎样才能做数据类所做的事情,并且有一个漂亮干净的名字而不需要反射呢?