我有一个Java接口:
public interface FooJava {
void consume(String... strings);
void consume(Integer... ints);
}
我想在Scala中实现它:
class BarScala extends FooJava {
override def consume(strings: String*): Unit = ???
override def consume(ints: Integer*): Unit = ???
}
不幸的是,这失败了:
double definition:
override def consume(strings: String*): Unit at line 4 and
override def consume(ints: Integer*): Unit at line 5
have same type after erasure: (strings: Seq)Unit
override def consume(ints: Integer*): Unit = ???
我知道Java编译器创建Bridge方法,而Scala编译器不这样做。
我尝试了一种使用DummyImplicates的方法:Are DummyImplicits used, and if so, how?,但它显然失败了-consume(ints: Integer*)(implicit i: DummyImplicit)
没有覆盖任何内容
class BarScala extends FooJava {
override def consume(strings: String*): Unit = ???
override def consume(ints: Integer*)(implicit i: DummyImplicit): Unit = ???
}
我没有Java接口。有可能在Scala中实现它吗?我使用Scala 2.12
1条答案
按热度按时间v8wbuo2f1#
你可以在Java中用中间抽象类实现接口,在Scala中扩展这个抽象类
或者不带
DummyImplicit