Scala: Is there a default class if no class is defined? -


According to

, Scala methods belong to a class. However, if I define a method in REPL or in a script that I execute using Scala, then which class is the method?

  Scala> Def Hoho (string: string) = {printlen ("hoho" + ARR)} Hoho: (String: Unit Scale & gt; Hoho ("Rehul") hooh rahul   

In this example Which class is related to the method?

REPL automatically declares all your statements in the objects (in fact your Wrapping the statement) if you print the intermediate code using the -Xprint: typer option, you see it in action Definition:

  scala> Def hoho (straight: string) = {println ("hoho" + straw)} [[syntax tree at the end of the tipper]] / scala source: & Lt; console & gt; package $ line1 {last object read $ java.lang.object with scalaObject {def this (): object $ line1. $ Read = {$ read.super.this (); ()}; The last object increases java.lang.Object with the $ iw slab object {df (this): object $ line 1. $ Read. $ Iw = {$ iw.super.this (); ()}; The last object $ Increases java.lang.Object with iw slab object {df this (): Object $ line1. $ Read $ Iw $ Iw = {$ iw.super.this (); ()}; Def hoho (str: string): unit = scale.a.prudiff.println ("hoho". (Str))}}}}   

then your method should be < / Code> Really $ line1 Have read $. $ Iw $ Iw.hoho Then when you use yes ("foo") , then it will be rewritten to add the package and external object

Additional Notes: For scripts, -Xprint: typer ( -Xprint: parser ) code is wrapped inside code block main (arguments: array [ String]) the main of an object. You have access to arguments in the form of args or argv .

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -