kensen john
kensen john

Reputation: 5519

Scala error - error: not found: type

I am a Java developer trying to learn Class creation in Scala.

I create two separate scala files. One file contains a trait. The second file extends the trait and defines a method.

Cola.scala This contains the trait.

trait Cola
{
        def fizz(): String
}

Pepsi.scala This has a class that tries to extend the trait.

class Pepsi extends Cola
{
        override def fizz():String = "1 Sugar"
}

var p = new Pepsi
println( " p = " + p.fizz )

When I excecute "scala Pepsi.scala" I get the following error message:

 error: not found: type Cola
class Pepsi extends Cola

Both files are in the same folder.

Please help how to resolve this? I am using Scala 2.8 I am not using an editor so that I will be forced from scratch. This is to improve my knowledge about computers.

Upvotes: 7

Views: 11133

Answers (2)

Ben Jackson
Ben Jackson

Reputation: 93720

Scala doesn't require you to put all of your traits and classes into eponymous (that is, named the same as the class) files. You can simply put all of that in one file and it will work. Or you can specify both files on the command line: Scala will not automatically look for Cola in Cola.scala.

Upvotes: 8

Ian McLaird
Ian McLaird

Reputation: 5585

Try compiling them both and running them like you would a java command:

scalac Cola.scala Pepsi.scala

scala -classpath . Pepsi

Upvotes: 9

Related Questions