Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala error - error: not found: type

Tags:

scala

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.

like image 820
kensen john Avatar asked Jul 22 '11 05:07

kensen john


1 Answers

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

scalac Cola.scala Pepsi.scala

scala -classpath . Pepsi

like image 184
Ian McLaird Avatar answered Oct 13 '22 13:10

Ian McLaird