score:7
Accepted answer
Remove the abstract
keyword and turn the class Expr
into object Expr
. As far as your code goes I see no reason to don't make these changes.
But, if you indeed want to keep you Expr
an abstract class you will have to extend and instantiate it:
def main(args:Array[String]) {
val expr = new Expr {} // extending the class - this creates a anonymous class
val v = expr.Var("x")
// alternatively, since now we do have a object to import
import expr._
val v2 = Var("x")
// even another approach, now using a named class
class MyExpr extends Expr
val myexpr = new MyExpr
val v3 = myexpr.Var("x")
}
Explanations:
- Only objects and packages can have its members imported
- Abstract classes have to be extended in order to be instantiated. The idea here is that some "point(s)" in class will is required to be defined by the client while still sharing the rest of interface with other extensions of the abstract class.
Source: stackoverflow.com
Related Query
- Invoke a case class from a main method within an object
- Read case class object from string in Scala (something like Haskell's "read" typeclass)
- Can't access method of companion class from companion object
- In Scala is there a way to reference the Companion Object from within an instance of a Case Class?
- Diffrence between extends from App and object contain main method in scala
- Working only when case class defined outside main method to create Dataset[case class] or Dataframe[case class]
- scala case class copy method is unseen from java code
- Sealed Trait / Object Case Class Byte Code Changed from 2.9.1. to 2.9.2?
- scala - how to access a case class method from another class?
- Can I invoke case class copy method with dynamic parameter without explicit reflection?
- In ScalaPb, How to create a case object and case class extending from the same trait?
- Import implicits from object that passed as method parameter vs class constructor parameter
- Access companion object from case class (or vice-versa) using scala type macros
- Scala selects wrong implicit conversion from within implicit class method
- Retrieve fieldname and value from case class object in scala, at runtime
- Which is faster for comparing case class object in scala : a) equals(==) method or b) equating hash values
- MongoDB Scala driver. How to update only changed document's fields from the case class object
- Type mismatch on moving method from companion object to a class
- How to get the class of a trait within an object defined in scala from within a java class?
- How to invoke public static method for existing Java class instance from Scala?
- How to return a List of case class from a method in scala
- Get object of case class from regex match
- How to use Scala case class from another Object
- Bring implicit parameter into scope from within case class body
- Scala: use case class from Main
- Create a ListMap[String,Int] from a JSON string to use within a case class
- convert json string to case class object from given json string and type of case class
- Use scala macros to copy method from class to companion object
- Get case class and JSON object from a hierarchical JSON map with lift-json
- how to create a Form from an object of case class
More Query from same tag
- Remove JSON array element in scala
- actual argument play.data.Form cannot be converted to play.api.data.Form
- Scala - Initialize an empty mutable SynchronizedHashMap
- Scala avoid Thread sleep for asynchronous test cases
- liftScreen validate custom fields
- Scala - override a class method in a trait
- Scala: Declare a variable for holding a function (lambda) without immediate assignment
- Scala package throws java.lang.UnsupportedClassVersionError
- Can't import RegexParsers
- Get distinct Combination of item pairs from Array[String] Column
- How do update a single cell of Scala Dataframe?
- why is my code not returning anything ? Scala fs2
- No Java class corresponding to Product with Serializable with Base found
- Can a partially applied function be extracted or interrogated for the applied parameter value
- Scala Future[Option[T]] Un Packing
- How to get columns of a spark sql query without execution
- when save record it'cause java.util.prefs.BackingStoreException: Raw Records don't save themselves
- Override default compile task in sbt
- Not persisting Scala None's instead of persisting as null value
- Why does Scala query return as unit?
- Serializing a Scala List to JSON in Play2
- Warnings following upgrade of play2-reactivemongo from version 0.18.4 to 0.19.5
- Scalatest aborted tests handling
- Filter a Dataframe using a subset of it and two specific fields in spark/scala
- DynamoDB - remove from set for items based on a non-key condition
- How does Scala handle tuples containing JVM primitive values?
- In scala can I pass repeated parameters to other methods?
- Spark/Scala Error - printing out Confusion Matrix for Logistic Regression
- Run-time Error when Deserializing Trait
- Spark dataset fetching data same as header for integer column