@field:Inject
private lateinit var mCommentApplication: CommentApplication
@field:Inject
private lateinit var models: Models
プロパティやプライマリコンストラクタのパラメータにアノテーション
→ 複数の Java 要素がターゲットになりうる
class Example(@field:Ann val foo, // annotate Java field
@get:Ann val bar, // annotate Java getter
@param:Ann val quux) // annotate Java constructor parameter
lateinit
)lateinit
修飾子を付ける!@field:Inject
private lateinit var models: Models
@Path("/comments")
@RequestScoped
open class CommentController {
@field:Inject
private lateinit var mCommentApplication: CommentApplication
@Controller
@GET
@Produces("text/html")
open fun getTest(): Response {
mModels.put("comments", mCommentApplication.readComments())
return Response.ok("comments.jsp").build()
}
}
open
アノテーションfinal
final
open
アノテーションで継承可能にopen
を付ける@Entity
@Table(name = "comment")
@NamedQuery(name = "Comment.findAll", query = "SELECT c FROM Comment c")
class Comment(text: String) : Serializable {
companion object {
private const val serialVersionUID = 1L
}
@field:Column(name = "text")
var text: String = text
}
fun EntityManager.createNamedQueryCommentFindAll() =
this.createNamedQuery("Comment.findAll", Comment::class.java)
class Key(val value: Int) {
companion object {
@JvmField
val COMPARATOR: Comparator<Key> = compareBy<Key> { it.value }
}
}
KotlinClass::class
というリテラルKClss
クラスのオブジェクトClass
を得るには #java
プロパティval c = MyClass::class.java
fun EntityManager.createNamedQueryCommentFindAll() =
this.createNamedQuery("Comment.findAll", Comment::class.java)