Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Scala对象的类设置为Java注释的字段_Java_Scala_Reflection_Annotations - Fatal编程技术网

将Scala对象的类设置为Java注释的字段

将Scala对象的类设置为Java注释的字段,java,scala,reflection,annotations,Java,Scala,Reflection,Annotations,我有如下Java注释: @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface ConvertWith { Class<? extends Converter> converterClass(); } 我希望使用以下对象将其与字段关联: class SampleAction { @ConvertWith(converterClass = classOf[IntConve

我有如下Java注释:

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ConvertWith {
  Class<? extends Converter> converterClass();
}
我希望使用以下对象将其与字段关联:

class SampleAction {
  @ConvertWith(converterClass = classOf[IntConverter])
  val x: Int = 0
}
但是,Scala找不到转换器类,因为scalac编译对象的方式不同

我也尝试过以下方法,但没有一种有效:

// error: class type required but IntConverter.type found
@ConvertWith(converterClass = classOf[IntConverter.type])

// error: annotation argument needs to be a constant...
@ConvertWith(converterClass = IntConverter.getClass)
有办法做到这一点吗?你有什么想法吗


提前感谢。

我会坚持使用java InteropyYou的类也可以同时使用:
类IntConverter扩展Converter。。。;对象IntConverter扩展IntConverter
// error: class type required but IntConverter.type found
@ConvertWith(converterClass = classOf[IntConverter.type])

// error: annotation argument needs to be a constant...
@ConvertWith(converterClass = IntConverter.getClass)