In Scala, classes can have Type Members and Value Members, I am just wondering what is the difference between these two and when would you use one of these.
Value members (or rather term members) are class members that represent some value.
These are: def
s, val
s, var
s and inner object
s.
Type members are members that represent a type. These are inner classes, traits and abstract types or type aliases (declared or defined with keyword type
).
abstract class A {
// examples of term members
val someVal = 5
var someVar = 0
def someMethod(someParam: Int) = someParam * 2
object someInnerObject
// examples of type members
type SomeTypeAlias = List[String]
type SomeAbstractType
trait SomeInnerTrait
class SomeInnerClass
}
I don't know if there is anything more significant to say about this classification. I hope someone can give some more general explanation if there is one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With