Support for Java annotations with arguments


#1

I attempted to write a simple Jersey-based webapp, which requires an annotation on a class of the form

@Path("/foo")

When I compile a Kotlin class annotated with this annotation

Path("/foo")
class Hello() {

}

I got a compile time error

[INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.goldin.plugins:kotlin-maven-plugin:0.2.3.8-beta-6:compile (compile-kotlin-sources) on project jersey-kotlin: Execution compile-kotlin-sources of goal com.goldin.plugins:kotlin-maven-plugin:0.2.3.8-beta-6:compile failed: java.lang.UnsupportedOperationException: Only annotations without values are supported by backend so far -> [Help 1] [ERROR]

...

Is there a YouTrack issue I can follow to learn when Java annotations with arguments are supported in Kotlin?  

Thanks.


#2

You should write an annotation in square parentheses.

For example:

[Path("/foo")]
class Hello() {

}


#3

Thanks.

I’m still getting the compile error even if using square brackets

import javax.ws.rs.Path import javax.ws.rs.GET

[Path("/hello")]
class HelloResource() {

  [GET]
  fun getHello() : String {
  return “hello”
  }
}


#4

Unfortunately, as I understand, currently there is only basic support for annotations.


#5

I know there is a lot on the plate of the Kotlin language team.  But I'm reminded of the guidance the Scala folks give when asked how to get started at work with the language:  write some tests with it.

So today in Kotlin with JUnit4 annotations I can do

``

  Test
  fun testChimp() {
  // blah
  }

But as I understand it, I cannot do

``

  Test(expected = RuntimeException.class)
  fun testChimpExectsError() {
  // blahblah
  }

because annotations with arguments are not yet supported.

So I’m thinking the sooner annotations with arguments are supported, the sooner you can pull in the people who can justify to their managers that they can get started at work with Kotlin by coding some of their unit tests with it.

Is there a Kotlin issue around adding annotation argument support?  If yes, I’ll vote for it.

Thanks much.


#6

here is it: http://youtrack.jetbrains.com/issue/KT-1522


#7

Please vote for it - I'm itching for this issue to be resolved too :)


#8

Yeah, I'm really looking forward to getting a feel for what a Jersey webapp looks like coded in Kotlin.  And for that you need annotations that take arguments.