static

Setting lazy static variable first initializes then assigns?

时间秒杀一切 提交于 2020-01-14 19:44:21
问题 I realize that static variables are implicitly lazy , which is really great. Doing the below will not create the instance until it's first called: static var test = Test() However, assigning a new instance to the static variable initializes the original, then assigns the new instance which is troubling for me: SomeType.test = AnotherTest() //Initializes Test then AnotherTest type To give more context on what I'm trying to do, I'm trying to setup a pure Swift dependency injection using this

JTextField disappears on some pages when being static, while appearing on others

梦想与她 提交于 2020-01-14 19:44:07
问题 While working on a program, I made some of my fields static i.e. a JTextField for a E-Number . But now this field behaves not as expected, on some of my pages it appears, on some others it disappears. Since I am not very experienced working with a lot of statics, there might be a concept I am not understanding. I have created a very simplified but working example of my program (MCVE) if you want to test it. It shows my overview page at first - the E-Number JTextField is missing. If you click

Java容器系列-HashMap源码分析

人走茶凉 提交于 2020-01-14 17:57:11
HashMap 实现了 Map 接口。HashMap 使用的很广泛,但不是线程安全的,如果在多线程中使用,必须需要额外提供同步机制(多线程情况下推荐使用 ConCurrentHashMap)。 HashMap 的类图相对简单,主要就是继承了 AbstractMap,有一点需要注意,虽然没有实现 Iterable 接口,但 HashMap 本身还是实现了迭代器的功能。 本文基于 JDK1.8 成员变量及常量 HashMap 是一个 Node[] 数组,每一个下标称之为一个 桶 。 每一个键值对都是使用 Node 来存储,这是一个单链表的数据结构。每个桶上可以通过链表来存储多个键值对。 常量 HashMap 中用到的常量及其意义如下: // 初始容量(桶的个数) 2^4 static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // 最大容量(桶的个数) 2^30static final int MAXIMUM_CAPACITY = 1 << 30;// 默认的装载因子(load factor),除非特殊原因,否则不建议修改static final float DEFAULT_LOAD_FACTOR = 0.75f;// 单个桶上的元素个数大于这个值从链表转成树(树化操作)static final int TREEIFY_THRESHOLD

部署你的CRM程序

筅森魡賤 提交于 2020-01-14 15:57:05
部署你的CRM程序 发布CRM你将使用以下软件 nginx uWSGI CentOS7 CRM项目文件 virtualenv supervisor WSGI、uWSGI python web服务器开发使用WSGI协议(Web Server Gateway Interface) python web项目默认会生成一个wsgi.py文件,确定好应用模块。 生产环境中使用的是uWSGI,实现了WSGI所有接口,C语言编写,效率很高的web服务器。 uWSGI是一个全功能的HTTP服务器,实现了WSGI协议、uwsgi协议、http协议等。它要做的就是把HTTP协议转化成语言支持的网络协议。比如把HTTP协议转化成WSGI协议,让Python可以直接使用。 Nginx 使用nginx是为了它的反向代理功能,项目会通过Django+uWSGI+Nginx进行服务器线上部署。 CentOS 1.打包项目CRM文件夹,压缩文件 2.通过xftp、scp、lrzsz等上传文件至Centos服务器 Linux使用技巧 1.通过xshell或者iTerm等软件,多终端操作你的linxu,这样对uwsgi、nginx、项目代码调试的时候,避免来回切换目录,提供工作效率。 2.注意修改了linux软件的配置文件,都要重启服务才能生效。 Virtualenv 构建一个干净,隔离的python解释器环境

讨论Java中的内部类是什么?

99封情书 提交于 2020-01-14 14:47:56
目录 前言 what is that? 成员内部类 局部内部类 匿名内部类 why use it? how to use? 前言 内部类,讲完前面的特性,今天就讲下内部类这个用的比较多,出现频率挺高的知识点。 what is that? 首先,顾名思义,内部类就是在类的内部,也就是类的类,嵌套在里面的。直接代码介绍,现一般分为成员内部类和局部内部类,还有一种匿名类。内部类拥有对外围对象的引用。大部分使用的都是成员内部类。 成员内部类 是一种与Field、方法、构造器和初始化块相似的类成员; 局部内部类和匿名内部类 则不是类成员。 成员内部类 定义在类里面的成员变量域的类,就是成员内部类。此时的内部类作为其外部类的成员,所以可以使用任意访问控制符如private、protected和public等修饰。 class A { //成员内部类,这种包含类的结构 class b{} } 成员内部类还可以分为静态内部类和非静态内部类。注意: 根据静态成员不能访问非静态成员的规则,外部类的静态方法、静态代码块不能访问非静态内部类,包括不能使用非静态内部类定义变量、创建实例等。 静态内部类(带static) static关键字的作用是把类的成员变成 类相关 ,而 不是 实例相关,即static修饰的成员属于 整个 类,而不属于单个对象。静态内部类只可以访问静态的外部类的方法和对象。但是静态内部类

Can't capture a static variable in a lambda [duplicate]

醉酒当歌 提交于 2020-01-14 12:41:27
问题 This question already has answers here : Capturing a static variable by reference in a C++11 lambda (2 answers) Closed last month . This seems strange, I can capture the static variable, but only if the variable isn't specified in the capture list, i.e., it implicitly captures it. int main() { int captureMe = 0; static int captureMe_static = 0; auto lambda1 = [&]() { captureMe++; }; // Works, deduced capture auto lambda2 = [&captureMe]() { captureMe++; }; // Works, explicit capture auto

Can't capture a static variable in a lambda [duplicate]

一个人想着一个人 提交于 2020-01-14 12:40:10
问题 This question already has answers here : Capturing a static variable by reference in a C++11 lambda (2 answers) Closed last month . This seems strange, I can capture the static variable, but only if the variable isn't specified in the capture list, i.e., it implicitly captures it. int main() { int captureMe = 0; static int captureMe_static = 0; auto lambda1 = [&]() { captureMe++; }; // Works, deduced capture auto lambda2 = [&captureMe]() { captureMe++; }; // Works, explicit capture auto

Java中main方法方法格式的解释

♀尐吖头ヾ 提交于 2020-01-14 12:17:14
  java中Main方法的标准命名规范为:public static void main(String[] args)   关于main方法的命名,为什么是使用public static void main来修饰,突然想到了这个问题于是自己查了一下。   在java中,设计者设计为main()方法是java应用程序的入口方法,也就是说,程序在运行的时候,第一个执行的方法就是main()方法,这个方法和其他的方法有很大的不同,比如方法的名字必须是main,方法必须是public static void类型的,方法必须是接受一个字符串数组的参数等。 因为main()方法是由Java 虚拟机 调用的,所以必须是public,虚拟机调用的main()方法的时候,不需要产生任何对象,所以main()方法声明为static,且不需要返回值,所以必须声明为void。static声明的方法不用实例就可以使用。不声明为static的话,使用main方法的时候还要对整个类进行初始化。而main又是程序的入口,只有进入入口才能实例化类(个人理解)。这样一边等着进入口,另一边却等着要先进入口再实例化,程序就无法运行。java很多基础语法继承与C等其他语言,而main方法作为程序的主入口早已是默认的常识,所以java设计者将main设计为static(纯属个人猜测)。 main()方法中有一个输入参数

JAVA中的static方法

不想你离开。 提交于 2020-01-14 11:42:08
  static表示“全局”或者“静态”的意思,用来修饰成员变量和成员方法,也可以形成静态static代码块,但是Java语言中没有全局变量的概念。   被static修饰的成员变量和成员方法独立于该类的任何对象。也就是说,它不依赖类特定的实例,被类的所有实例共享。只要这个类被加载,Java虚拟机就能根据类名在运行时数据区或者方法区内找到他们。因此,static对象可以在它的任何对象创建之前访问,无需引用任何对象。   用public修饰的static成员变量和成员方法本质是全局变量和全局方法,当声明它类的对象时,不生成static变量的副本,而是类的所有实例共享同一个static变量。   static变量前可以有private修饰,表示这个变量可以在类的静态代码块中,或者类的其他静态成员方法中使用(当然也可以在非静态成员方法中使用),但是不能在其他类中通过类名来直接引用,这一点很重要。实际上你需要搞明白,private是访问权限限定,static表示不要实例化就可以使用,这样就容易理解多了。static前面加上其它访问权限关键字的效果也以此类推。   static修饰的成员变量和成员方法习惯上称为静态变量和静态方法,可以直接通过类名来访问,访问语法为:   类名.静态方法名(参数列表...)   类名.静态变量名   用static修饰的代码块表示静态代码块,当Java虚拟机

Ensuring Thread-Safety On Static Methods In C#

旧时模样 提交于 2020-01-14 09:36:09
问题 I've got some code I currently have in a static class/method, but I wanted to check that it would be thread-safe. From what I've read I think this should be ok, but something in the back of my mind is saying it might not be. My web page's data processing stage uses an external web service to create order records, and this could be quite slow: possibly 30-40 seconds to, possibly, 5 or 10 minutes (this is out of my hands) so I was going to fire a return page back to the user, then start a new