commit
74ef43fb91
|
@ -0,0 +1,31 @@
|
|||
package com.baeldung.jvmannotations
|
||||
|
||||
import java.util.*
|
||||
|
||||
interface Document {
|
||||
|
||||
@JvmDefault
|
||||
fun getType() = "document"
|
||||
}
|
||||
|
||||
class TextDocument : Document {
|
||||
override fun getType() = "text"
|
||||
|
||||
fun transformList(list : List<Number>) : List<Number> {
|
||||
return list.filter { n -> n.toInt() > 1 }
|
||||
}
|
||||
|
||||
fun transformListInverseWildcards(list : List<@JvmSuppressWildcards Number>) : List<@JvmWildcard Number> {
|
||||
return list.filter { n -> n.toInt() > 1 }
|
||||
}
|
||||
|
||||
var list : List<@JvmWildcard Any> = ArrayList()
|
||||
}
|
||||
|
||||
class XmlDocument(d : Document) : Document by d
|
||||
|
||||
fun main() {
|
||||
val myDocument = TextDocument()
|
||||
val myTextDocument = XmlDocument(myDocument)
|
||||
println("${myDocument.getType()} ${myTextDocument.getType()}")
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.baeldung.jvmannotations;
|
||||
|
||||
public class HtmlDocument implements Document {
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "HTML";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
@file:JvmName("MessageHelper")
|
||||
@file:JvmMultifileClass //used
|
||||
package com.baeldung.jvmannotations
|
||||
|
||||
import java.util.*
|
||||
|
||||
@JvmName("getMyUsername")
|
||||
fun getMyName() : String {
|
||||
return "myUserId"
|
||||
}
|
||||
|
||||
object MessageBroker {
|
||||
@JvmStatic
|
||||
var totalMessagesSent = 0
|
||||
|
||||
const val maxMessageLength = 0
|
||||
|
||||
@JvmStatic
|
||||
fun clearAllMessages() {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
@Throws(Exception::class)
|
||||
fun findMessages(sender : String, type : String = "text", maxResults : Int = 10) : List<Message> {
|
||||
if(sender.isEmpty()) {
|
||||
throw Exception()
|
||||
}
|
||||
return ArrayList()
|
||||
}
|
||||
}
|
||||
|
||||
class Message {
|
||||
|
||||
// this would cause a compilation error since sender is immutable
|
||||
// @set:JvmName("setSender")
|
||||
val sender = "myself"
|
||||
|
||||
// this works as name is overridden
|
||||
@JvmName("getSenderName")
|
||||
fun getSender() : String = "from:$sender"
|
||||
|
||||
@get:JvmName("getReceiverName")
|
||||
@set:JvmName("setReceiverName")
|
||||
var receiver : String = ""
|
||||
|
||||
@get:JvmName("getContent")
|
||||
@set:JvmName("setContent")
|
||||
var text = ""
|
||||
|
||||
// generates a warning
|
||||
@get:JvmName("getId")
|
||||
private val id = 0
|
||||
|
||||
@get:JvmName("hasAttachment")
|
||||
var hasAttachment = true
|
||||
|
||||
var isEncrypted = true
|
||||
|
||||
fun setReceivers(receiverNames : List<String>) {
|
||||
}
|
||||
|
||||
@JvmName("setReceiverIds")
|
||||
fun setReceivers(receiverNames : List<Int>) {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
@file:JvmMultifileClass
|
||||
@file:JvmName("MessageHelper") //applies to all top level functions / variables / constants
|
||||
package com.baeldung.jvmannotations
|
||||
|
||||
fun convert(message: Message) {
|
||||
}
|
Loading…
Reference in New Issue