この非常に単純なコードを使用する
import java.util.Properties
class MyProperties extends Properties
object MyProperties {
def get(): MyProperties = new MyProperties
def anotherMethod(): MyProperties = new MyProperties
}
get()コンパイルされたコードにメソッドがありません。クラスのJava逆コンパイルにより、MyProperties(scalaシグネチャは省略されます)
import java.util.Properties;
import scala.reflect.ScalaSignature;
public class MyProperties extends Properties
{
public static MyProperties anotherMethod()
{
return MyProperties..MODULE$.anotherMethod();
}
}
ただし、MyProperties拡張しない場合は、メソッドが生成されます。java.util.Propertiesget()
java.util.Propertiespublic V get(Object key)fromを継承しますjava.util.Dictionaryが、これは異なるシグネチャを持つ非静的メソッドです。
get()生成されたバイトコードに(静的)メソッドがないのはなぜですか?
Scala 2.10.1-rc2-JVM 1.6.0_41
2.10.0で同じ問題を編集
編集2 これはJavaで「機能」します
import java.util.Properties;
public class MyPropertiesjava extends Properties {
private static final long serialVersionUID = 1L;
public static MyProperties get() {
return new MyProperties();
}
public static MyProperties antotherMethod() {
return new MyProperties();
}
}
編集3 以下のRégis回避策の小さな編集(タイプを「グローバル」にすることはできません)
import java.util.Properties
class MyPropertiesImpl extends Properties
object MyProperties {
type MyProperties = MyPropertiesImpl
def get(): MyProperties = new MyPropertiesImpl
def anotherMethod(): MyProperties = new MyPropertiesImpl
}
Typesafeチームが追跡した4つの問題をここで編集