简体   繁体   English

Scala中“ object”关键字的意义是什么?

[英]What is the significance of “object” Keyword in Scala?

I am a novice in Scala. 我是Scala的新手。 I am trying to code in Scala, Below is the syntax of how a program starts: 我正在尝试在Scala中编写代码,以下是程序启动方式的语法:

object demo
{
  //do your stuff..............
}

What is the Significance of that?? 那有什么意义? Is it like mother of all the classes defined??? 就像所有已定义类的母亲一样吗???

Any help would be helpful. 任何帮助都会有所帮助。

class is a definition, a description. 类是定义,描述。 It defines a type in terms of methods and composition of other types. 它根据方法和其他类型的组成来定义类型。

An object is a singleton -- an instance of a class which is guaranteed to be unique. 对象是单例-保证类的实例是唯一的。 For every object in the code, an anonymous class is created, which nherits from whatever classes you declared object to implement. 对于代码中的每个对象,都会创建一个匿名类,该匿名类继承于您声明要实现的对象的任何类。 This class cannot be seen from Scala source code -- though you can get at it through reflection. 从Scala源代码中看不到此类,尽管您可以通过反射来了解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM