The atypical Scala program and its compiled results

Source: Internet
Author: User

Beginner Scala

Folder structure and part of the code

Package.scala's Code

Package  COMX Package       object mypkg {      def myprint = println ("Hello Ji2 on Package object")  }  Object Myp kg2{     def myprint = println ("Hello Ji2 in Object")  

Command line

>scalac Mypkg/package.scala Newt.scala

>scala Test2


Hello Ji2 in Package object () Hello Ji2 in Package object () Hello Ji2 in Object ()



Code beginner Good time, src below only a file Newt.scala and a folder mypkg, connotation Package.scala,

After the implementation of the SCALAC, SRC below a few more classes, more than a COMx folder

COMx folder

Mypkg folder


1 Scala's package statement specifies where the class file is generated, even if it does not already exist

2 package Object definition file Package.scala should be in Mypkg folder

3 The class file for object is under the folder specified by the package

The 4.package object has no corresponding class, and in Package.class, it becomes the package comx.mypkg, which becomes the first layer of the pakage structure.

5. Newt.scala, the name of object is Test2, so the parameters of the Scala command are Test2, not newt, otherwise the error

PostScript, for the 2nd I did another experiment

Put Src/mypkg-MYPKG2, the documents Package.scala->package_n.scala,

Package_n.scala adds a Package object definition

    Package Object Mypkg3 {      def myprint = println ("Hello Ji3 in Package Object")  }

The difference between the results and the last

COMx below became two folder:mypkg & Mypkg3


The name of the package object definition file is arbitrary, the folder name is also arbitrary,

Instead, the name of each package object generates a folder with its own definition of Class:package.class & Package$.class

The atypical Scala program and its compiled results

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.