0
를 실행 가져올 수 없습니다 이것이 패키지를 사용하기 때문에 조금 혼란 스럽네요. 나는나는이 개 질문이 스칼라 파일
scalac Fruits.scala
scala bobsdelight\Fruits
를 사용하여이 작업을 실행하려고하지만, 사람이 얼마나 좋은 것이 스크립트를 실행하는 방법 보여주세요 수 있다면 나는
java.lang.NoClassDefFoundError: bobsdelights\Fruits wrong name: bobsdelights/Fruits)
을 얻을
2)가도를 만들려고 해요 먼저 파일을로드하여 REPL에서 new Fruits.Apple
를 호출하여 새로운 애플 객체하지만 난 얻을 :
error: type Apple is not a member of object Fruits
new Fruits.Apple``
이 예는 스칼라에서 프로그래밍에 도서.
package bobsdelights
abstract class Fruit(
val name: String,
val color: String
)
object Fruits {
object Apple extends Fruit("apple", "red")
object Orange extends Fruit("orange", "orange")
object Pear extends Fruit("pear", "yellowish")
val menu = List(Apple, Orange, Pear)
}
Fruits.scala의 전체 콘텐츠를 삭제할 수 있습니까? – Pavel
그것이 전부입니다. – zam
실제 클래스 정의 Fruits를 만듭니다. Singelton은 Fruits $ 등 다른 클래스를 가지고 있습니다. – Pavel