- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Why do I need to initialize every member
Mon, 2011-05-23, 20:51
For example,
class Persist extends Logging { var connector: Connect = new Connect var client: Cassandra.Client = connector.connect
I would expect to be able to say
var connector: Connect
but this does not compile. At least can I set it to some kind of null?
Thank you,Mark
class Persist extends Logging { var connector: Connect = new Connect var client: Cassandra.Client = connector.connect
I would expect to be able to say
var connector: Connect
but this does not compile. At least can I set it to some kind of null?
Thank you,Mark
Mon, 2011-05-23, 22:17
#2
Re: Re: Why do I need to initialize every member
On Mon, May 23, 2011 at 12:56 PM, Ken McDonald <ykkenmcd@gmail.com> wrote:
Interesting. I was not aware of that feature. What exactly does it do?
--Russ P
--
http://RussP.us
say
var connector: Connect = _
when you simply say
var connector: Connect
your are declaring "connector" as an abstract var.
Ken
Interesting. I was not aware of that feature. What exactly does it do?
--Russ P
--
http://RussP.us
Mon, 2011-05-23, 22:27
#3
Re: Re: Why do I need to initialize every member
On Mon, May 23, 2011 at 11:03 PM, Russ Paielli wrote:
> On Mon, May 23, 2011 at 12:56 PM, Ken McDonald wrote:
>> var connector: Connect = _
> Interesting. I was not aware of that feature. What exactly does it do?
See Section 4.2 "Variable Declarations and Definitions" (p 40) of the spec. [1]
"A variable definition var x: T = _ can appear only as a member of a
template. It introduces a mutable field with type T and a default
initial value. The default value depends on the type T as follows:
[... 0 / false / () / null]
-jason
var connector: Connect = _
when you simply say
var connector: Connect
your are declaring "connector" as an abstract var.
Ken