Constructor in depth
There are two types of constructor:Instance Constructor and Type Constructor(or so-called Static Constructor).
Instance Constructor
When use the new key word to create an instance of class, it will do:
- Calculate the size of the class, including the sync block and the type object pointer, so that it knows how much memory the instance needs.
- Allocate memory.
- Call the the constructor,and it will call the constructor of the base class before the current constructor do anything, and so on to the constructor of the Object class.Note that
Constructor is the only way to initialize a instance or a type, We may have seen codes like below:
class SomeClass
{
private int aField = ;
public SomeClass()
{ }
}
you may think aField is initialized outside the constructor, but this is just a syntactic trick of c#。The compiler will gen some IL codes to set aField to 5 inside the constructor, AND, if there are more than one constructors, each one will contain that piece of IL initailling codes.
Constructor in depth的更多相关文章
- js in depth: arrow function & prototype & this & constructor
js in depth: arrow function & prototype & this & constructor https://developer.mozilla.o ...
- js in depth: Object & Function & prototype & __proto__ & constructor & classes inherit
js in depth: Object & Function & prototype & proto & constructor & classes inher ...
- Thread in depth 4:Synchronous primitives
There are some synchronization primitives in .NET used to achieve thread synchronization Monitor c# ...
- 【D3D12学习手记】4.3.8 Create the Depth/Stencil Buffer and View
我们现在需要创建深度/模板缓冲区. 如§4.1.5所述,深度缓冲区只是一个2D纹理,用于存储最近的可见对象的深度信息(如果使用模板(stencil),则也会存储模板信息). 纹理是一种GPU资源,因此 ...
- HOC in Depth
HOC in Depth Higher-Order Components https://reactjs.org/docs/higher-order-components.html 1. wrappe ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- 分析js中的constructor 和prototype
在javascript的使用过程中,constructor 和prototype这两个概念是相当重要的,深入的理解这两个概念对理解js的一些核心概念非常的重要. 我们在定义函数的时候,函数定义的时候函 ...
- js中的constructor
定义和用法 constructor 属性返回对创建此对象的 Date 函数的引用. 语法 object.constructor constructor属性不影响任何JavaScript的内部属性.in ...
- Java程序设计之Constructor
插入段代码,下次回忆吧. 先新建一个Person类,代码如下: public class Person { private String name ; private int age; public ...
随机推荐
- linux学习第三天 (Linux就该这么学)
今天是学习的第三天,讲了很多命令,又赶上双11,网络经常波动,我经常掉线,没有听到多少,回头再看一下录播.我也写一下讲的命令吧,也加深一下命令的印象.第三章老师讲完了. ifconfig命令:输出信息 ...
- NOIP训练测试3(2017081601)
上一波题还是比较水的吧?[?????] 也许吧! 但时间还是比较紧的,所以我从2.5个小时延长至3个小时了. 不管了,做题不能停,今天继续测试. 水不水自己看,我什么也不说(zhe shi zui h ...
- kbmmw 5.06.20 发布
经过1个多月的测试,终于发布正式版. 5.06.20 July 11 2018 Important notes (changes that may break existing c ...
- Java日期时间使用总结[转载]
Java日期时间使用总结 一.Java中的日期概述 日期在Java中是一块非常复杂的内容,对于一个日期在不同的语言国别环境中,日期的国际化,日期和时间之间的转换,日期的加减运算,日期的展示格式 ...
- JSAAS 平台实现 微信类似的TOKEN机制
在企业微信中,我们在调用微信接口时,我们需要首先获取token,然后根据token,调用API接口方法.这个token是有生命周期的,微信的token默认的生命周期是7200秒. 因此这个token可 ...
- 6. Uniforms in American's Eyes 美国人眼里的制服
6. Uniforms in American's Eyes 美国人眼里的制服 (1) Americans are proud of their variety and individuality,y ...
- python code(1)
from collections import UserList class MthChianList(UserList): def filter(self,predicste): return Mt ...
- python模块:sys
# encoding: utf-8 # module sys # from (built-in) # by generator 1.145 """ This module ...
- div配景图片全div显示
<div class="face-boy" style="width:86px;height:92px;background: url('/${userProfil ...
- 代码的二次重构(开篇:JDBC连接数据库)
Java中使用JDBC连接数据库时,若是使用初级的代码,代码复用率非常低,连接过程简单来说分为以下几个步骤: 加载驱动包 准备好URL链接获取数据库连接(driver和url根据不同的数据库的不同而不 ...