asad.awadia
02/18/2018, 7:11 PMWajid Ali
02/19/2018, 5:52 AMfred.deschenes
02/19/2018, 2:04 PMdeviant
02/20/2018, 3:27 PM@Entity
data class User(val id:Long) {
@Transient private val chunks = Set<String>() // this is always null when read from db
}
I use spring
, hibernate
and kotlin-jpa
plugin. When i read data from db with spring-data
the User
entity has all filled columns from the table. All good except that transient chunks
property. It is always null. As i understood kotlin-jpa
plugin generates empty constructor and uses it on entity instantiation. But the chunks
property initializes itself in normal constructor. Is there any workaround how can i initialize transient property?Marcelus Trojahn
02/20/2018, 3:40 PMdeviant
02/20/2018, 3:41 PMMarcelus Trojahn
02/20/2018, 3:42 PMMarcelus Trojahn
02/20/2018, 3:44 PMdeviant
02/20/2018, 3:47 PMdeviant
02/20/2018, 4:14 PM@Transient private var _chunks: MutableSet<Int>? = null
private val chunks: MutableSet<Int>
get() {
if (_chunks == null) _chunks = HashSet()
return _chunks!!
}
looks ugly. hope somebody suggest me a better solutionMarcelus Trojahn
02/20/2018, 4:29 PMdeviant
02/20/2018, 8:22 PMdeviant
02/21/2018, 8:27 AMEnable invokeInitializers option if you want the plugin to run the initialization logic from the synthetic constructor.
https://kotlinlang.org/docs/reference/compiler-plugins.html#no-arg-compiler-pluginfradiati
02/22/2018, 1:35 PMfradiati
02/22/2018, 1:35 PMfradiati
02/22/2018, 1:36 PMfradiati
02/22/2018, 1:36 PMfradiati
02/22/2018, 1:36 PMasad.awadia
02/22/2018, 3:14 PMorangy
bloder
02/22/2018, 7:31 PMtry {
clientSocket = DatagramSocket()
val ipAdresses = InetAddress.getByName(getBroadcast())
val sendData = ByteArray(1024)
clientSocket?.send(DatagramPacket(sendData, sendData.size, ipAdresses, dstPort))
clientSocket?.close()
} catch (e: Exception) {
if (clientSocket != null) clientSocket?.close()
}
I've already check this ipAddresses and it's correct for linux and windows and it doesn't generate any exception =/bloder
02/22/2018, 7:32 PMasad.awadia
02/22/2018, 8:16 PMbloder
02/22/2018, 9:22 PMorangy
Nursultan Nazarov
02/24/2018, 12:49 PMIshan Khare
02/25/2018, 11:47 AMbuildscript {
ext.kotlin_version = '1.2.21'
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-stdlib"
}
}
plugins {
id "org.jetbrains.kotlin.jvm" version "1.2.21"
}
sourceSets {
main.kotlin.srcDirs += "./"
}
I'm getting errors related to kotlin-stdlib
like
e: /home/ishan/code/kotlin-server/server/HttpRequest.kt: (8, 19): Unresolved reference: HashMap
e: /home/ishan/code/kotlin-server/server/HttpRequest.kt: (16, 38): Unresolved reference: split
e: /home/ishan/code/kotlin-server/server/HttpResponse.kt: (22, 31): Unresolved reference: toByteArray
e: /home/ishan/code/kotlin-server/server/HttpStatusCodes.kt: (3, 22): Unresolved reference: HashMap
e: /home/ishan/code/kotlin-server/server/HttpStatusCodes.kt: (3, 45): Unresolved reference: hashMapOf
Slack ConversationIshan Khare
02/25/2018, 11:47 AMkotlinc -include-runtime
commandrocketraman
02/25/2018, 6:38 PMclasspath "org.jetbrains.kotlin:kotlin-stdlib"
dependency should be in a dependencies
section, not inside buildscript/dependencies
.