scala - accessing constructor variable in companion object -


getting compile time error following classes in same file

class fancygreeting (greeting: string) {     //private var  greeting: string=_;      def greet() = {         println( "greeting in class" + greeting)     } }  object fancygreeting {      def privategreeting(f:fancygreeting) : string = {         f.greeting;     } } 

error: value greeting not member of this.fancygreeting f.greeting;

the same works if use private variable greeting instead of constructor

you should write class fancygreeting(private var greeting: string) { if want have same behavior when use line commented out. way write (i.e. class fancygreeting(greeting: string) {) giving greeting parameter constructor, without making property.

this said, should not use ";" end lines in scala. moreover, better use val var, if can.

note: this answer might interesting you.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -