scala-java-interop

Java static class members and Scala interoperability

泄露秘密 提交于 2021-02-07 21:54:20
问题 From the An Overview of the Scala Programming Language, Second Edition : // Scala object PrintOptions { def main(args: Array[String]): Unit = { System.out.println("Options selected:") for (val arg <- args) if (arg.startsWith("-")) System.out.println(" " + arg.substring(1)) } } In the example above, the Scala program invokes methods startsWith and substring of String , which is a class defined in Java. It also accesses the static out field of the Java class System , and invokes its (overloaded

Java static class members and Scala interoperability

别说谁变了你拦得住时间么 提交于 2021-02-07 21:53:44
问题 From the An Overview of the Scala Programming Language, Second Edition : // Scala object PrintOptions { def main(args: Array[String]): Unit = { System.out.println("Options selected:") for (val arg <- args) if (arg.startsWith("-")) System.out.println(" " + arg.substring(1)) } } In the example above, the Scala program invokes methods startsWith and substring of String , which is a class defined in Java. It also accesses the static out field of the Java class System , and invokes its (overloaded

Scala extra no-arg constructor plus default constructor parameters

拜拜、爱过 提交于 2021-02-07 01:57:30
问题 I am using the Scala 2.8 default parameters on a constructor, and for Java compatibility reasons, I wanted a no-arg constructor that uses the default parameters. This doesn't work for very sensible reasons: class MyClass(field1: String = "foo", field2: String = "bar") { def this() = { this() // <-- Does not compile, but how do I not duplicate the defaults? } } I am wondering if there is anything that I am missing. Any thoughts that don't require duplicating the parameter defaults? Thanks! 回答1

Scala extra no-arg constructor plus default constructor parameters

烈酒焚心 提交于 2021-02-07 01:53:38
问题 I am using the Scala 2.8 default parameters on a constructor, and for Java compatibility reasons, I wanted a no-arg constructor that uses the default parameters. This doesn't work for very sensible reasons: class MyClass(field1: String = "foo", field2: String = "bar") { def this() = { this() // <-- Does not compile, but how do I not duplicate the defaults? } } I am wondering if there is anything that I am missing. Any thoughts that don't require duplicating the parameter defaults? Thanks! 回答1

Scala extra no-arg constructor plus default constructor parameters

会有一股神秘感。 提交于 2021-02-07 01:51:14
问题 I am using the Scala 2.8 default parameters on a constructor, and for Java compatibility reasons, I wanted a no-arg constructor that uses the default parameters. This doesn't work for very sensible reasons: class MyClass(field1: String = "foo", field2: String = "bar") { def this() = { this() // <-- Does not compile, but how do I not duplicate the defaults? } } I am wondering if there is anything that I am missing. Any thoughts that don't require duplicating the parameter defaults? Thanks! 回答1

Scala extra no-arg constructor plus default constructor parameters

十年热恋 提交于 2021-02-07 01:50:14
问题 I am using the Scala 2.8 default parameters on a constructor, and for Java compatibility reasons, I wanted a no-arg constructor that uses the default parameters. This doesn't work for very sensible reasons: class MyClass(field1: String = "foo", field2: String = "bar") { def this() = { this() // <-- Does not compile, but how do I not duplicate the defaults? } } I am wondering if there is anything that I am missing. Any thoughts that don't require duplicating the parameter defaults? Thanks! 回答1

Implementing Multilevel Java Interfaces in Scala

爷,独闯天下 提交于 2021-01-27 04:42:33
问题 I have following hierarchy in java for my interface public interface Identifiable<T extends Comparable<T>> extends Serializable { public T getId(); } public interface Function extends Identifiable { public String getId(); } public abstract class Adapter implements Function { public abstract String getId(); } When I try to implement Adapter in scala as follows class MultiGetFunction extends Adapter { def getId() : String = this.getClass.getName } I am getting following error Multiple markers