https://kotlinlang.org logo
Title
j

jtonic

08/28/2017, 4:37 AM
Dear Kotlin community, Is it possible to convert the following java annotations to kotlin? I tried to make it w/o any luck. I thought @JvmField would be of any help, but wasn’t.
public class Profiles {

  @Target(ElementType.TYPE)
  @Retention(RetentionPolicy.RUNTIME)
  @Profile(Service1MockedProfile.NAME)
  public @interface Service1MockedProfile {

    String NAME = “Service1MockedProfile”;
  }

  @Target(ElementType.TYPE)
  @Retention(RetentionPolicy.RUNTIME)
  @Profile(Service2MockedProfile.NAME)
  @interface Service2MockedProfile {

    String NAME = “Service2MockedProfile”;
  }
}

@Service
@Profiles.Service1MockedProfile
class MyService {}

@ActiveProfiles(profiles = {Service1MockedProfile.NAME})
class MyServiceTest {}
o

orangy

08/28/2017, 7:46 AM
Please use triple backticks to quote long code. Thanks!
j

jtonic

08/28/2017, 6:12 PM
public class Profiles {

 @Target(ElementType.TYPE)
 @Retention(RetentionPolicy.RUNTIME)
 @Profile(Service1MockedProfile.NAME)
 public @interface Service1MockedProfile {

   String NAME = "Service1MockedProfile";
 }

 @Target(ElementType.TYPE)
 @Retention(RetentionPolicy.RUNTIME)
 @Profile(Service2MockedProfile.NAME)
 @interface Service2MockedProfile {

   String NAME = "Service2MockedProfile";
 }
}

@Service
@Profiles.Service1MockedProfile
class MyService {}

@ActiveProfiles(profiles = {Service1MockedProfile.NAME})
class MyServiceTest {}
Thank you Ilya for the suggestion. I took it into account. Do you know if it is possible to have a static final String in a kotlin annotation like we can do in java?