Scala constructor without parameters

Viewed 19934

I may be having a silly problem here... I can't seem to figure out how to make a constructor without parameters in Scala. I know I can just write the whole thing in the class body (especially because it's the only constructor I need), but it doesn't quite feel right.

What I have:

    class Foo {
        //some init code

        //...
    }

What I'd like (but doesn't work as it wants me to call another constructor first):

    class Foo {
        // The only constructor
        def this() = { 
            //some init code
        }

        //...
    }
4 Answers
Related