SHARE
TWEET

Untitled

a guest Sep 18th, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Me in the interpreter my first days of trying to understand
  2. // things about what I'm seeing trying to read Scala sources.
  3.  
  4. scala> class WhatDoesThisSyntaxDo() { println("Constructed, IG") }
  5. defined class WhatDoesThisSyntaxDo
  6. //A class declaration with a constuctor with a single empty parameter list (`()`), and a constuctor body `println("Constructed, IG")`
  7.  
  8. scala> new WhatDoesThisSyntaxDo
  9. Constructed, IG
  10. res0: WhatDoesThisSyntaxDo = WhatDoesThisSyntaxDo@20011bf
  11. //call the constructor -- you can leave off an empty parameter list. This is useful for java interop
  12.  
  13. scala> new WhatDoesThisSyntaxDo()
  14. Constructed, IG
  15. res1: WhatDoesThisSyntaxDo = WhatDoesThisSyntaxDo@7d3fb0ef
  16. //call the constructor
  17.  
  18. scala> class WhatDoesThisSyntaxDo { println("Constructed, IG") }
  19. defined class WhatDoesThisSyntaxDo
  20. //A class declaration with a constuctor without a parameter list, and a constuctor body `println("Constructed, IG")`
  21.  
  22. scala> new WhatDoesThisSyntaxDo
  23. Constructed, IG
  24. res3: WhatDoesThisSyntaxDo = WhatDoesThisSyntaxDo@316cda31
  25. //call the constructor
  26.  
  27. scala> new WhatDoesThisSyntaxDo()
  28. Constructed, IG
  29. res4: WhatDoesThisSyntaxDo = WhatDoesThisSyntaxDo@691567ea
  30. //An artifact of Java interop. The runtime can't see that the constructor doesn't have a parameter list. For a normal method this would be an error.
  31.  
  32. scala> new WhatDoesThisSyntaxDo { println("Wtf is this now") }
  33. Constructed, IG
  34. Wtf is this now
  35. res7: WhatDoesThisSyntaxDo = $anon$1@464aeb09
  36. //Call the constructor of an anonymous class that extends WhatDDoesThisSyntaxDo with a constructor with body `println("Wtf is this now")` which will be called after the parent constructor
  37.  
  38. scala> new WhatDoesThisSyntaxDo() { println("Wtf is this now") }
  39. Constructed, IG
  40. Wtf is this now
  41. res8: WhatDoesThisSyntaxDo = $anon$1@4fa0ee7e
  42. //Call the constructor of an anonymous class that extends WhatDDoesThisSyntaxDo with a constructor with body `println("Wtf is this now")` which will be called after the parent constructor
  43.  
  44. scala> class Unclear extends WhatDoesThisSyntaxDo { println("Wtf is this now") }
  45. defined class Unclear
  46. //Declare a class `Unclear` that extends WhatDoesThisSyntaxDo with a constructor without a parameter list with body `println("Wtf is this now")`
  47.  
  48. scala> new Unclear
  49. Constructed, IG
  50. Wtf is this now
  51. res10: Unclear = Unclear@6c9151c1
  52.  
  53. //Call the above constructor, which first calls its superclass constructor
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top