java - Declaring class level variable in scala -


i have started playing scala code bit java-ish. below code :

object typeparam extends app{    class param1[t](val elem: t*){     val elems : list[t] = elem.tolist     def toprint(): unit ={       elems.foreach(print)     }   }    @override   def main(args : list[string]): unit ={     val x= new param1[int](1,2,3,4,6,7)     x.toprint()   } }  

what expecting elements printed in realty not getting output.

i know can print list through foreach learning trying blend things up.

could explain why not getting output,so in scala not have class level variable can set ?

by using below syntax not overriding main method app trait, hence not see output.

@override def main(args : list[string]): unit ={ 

use below syntax override main method:

override def main(args: array[string]) {  

note use of override keyword. in scala, it's mandatory use override when overriding concrete method.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -