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
Post a Comment