Annotations at end of signature


#1

I find Kotlins coding style of putting method and class names up front to be very clean.  However when I use annotations the names get lost in the annotations.  Is it possible, now that kotlin is using the '@' prefix for annotations, to put them at the end of the declaration?

For Example, instead of

@Serialize data class Color(
  @Serailize(“red”) val red: Int,
  @Serailize(“green”) val green: Int,
  @Serialize(“blue”) val blue: Int
) {
  @Cachable(10) fun someMethod(): Int = 15
}  


It could be

class Color(
  val red: Int @Serailize(“red”),
  val green: Int @Serailize(“green”),
  val blue: Int @Serailize(“blue”)
): @data @Serialize {

  fun someMethod(): Int @Cachable(10) = 15
}

Or

class Color @data @Serialize(   val red @Serailize("red"): Int,   val green @Serailize("green"): Int,   val blue @Serailize("blue"): Int ): @data @Serialize {   fun someMethod() @Cachable(10): Int = }

This keeps the Identifiers up front, and puts the annotation in with the type definition

Just a thought, enjoying Kotlin

  • Matt

#2

I'd suggest you to write annotations on the previous line:

@Serialize
data class Color(
  @Serailize("red")
  val red: Int,
  @Serailize("green")
  val green: Int,
  @Serialize("blue")
  val blue: Int
) {
  @Cachable(10)
  fun someMethod(): Int = 15
}  

It's more lines, yes, but everything is visible