static

Variable and Method shadowing in Java

99封情书 提交于 2020-01-13 01:28:32
问题 Basically I would like to know why a static method cannot be shadowed by an instance method, (I know why, it will lead to ambiguity in certain circumstances), whereas a static variable can be shadowed by an instance variable (it applies only for subclasses). Example: public class Apartment{ static int area = 10; public static int getArea(){ return area; } } class BedroomFlat extends Apartment { int area = 10;// no problem at all public int getArea(){ // illegal line it cannot hide the super

How to see static or global variables in Eclipse CDT?

徘徊边缘 提交于 2020-01-12 20:55:09
问题 I have been trying to figure out how to display static variables in the eclipse variable window for the CDT and can't figure out how. The menu button for the CDT doesn't seem to have the java->globals menu. How do I display static/global variables in eclipse CDT debugger? 回答1: Window -> Show View -> Expressions You can add any expression there, so also global variables. 回答2: Arrow down button > Java > Show Constants / Show Static Variables 来源: https://stackoverflow.com/questions/4434107/how

java单例模式(剑指offer)

十年热恋 提交于 2020-01-12 11:57:32
实现Singleton 模式–七种实现方式 public class Test02 { /*单例模式,饿汉式,线程安全 *只要有先加载就让我吃,先写明私有的构造方法防止被new,然后九直接实例化,最后调用,不存在线程安全问题 * */ public static class Singleton01 { private static Singleton01 INSTANCE = new Singleton01 ( ) ; private Singleton01 ( ) { } public static Singleton01 getInstance ( ) { return INSTANCE ; } } public static class Singleton2 { /*单例模式,懒汉式,线程不安全 *饿了再找吃的,属于懒加载 *如果两个同时运行到判断instance是否为null的if语句,此时instance确实没有创建 *则两个线程都会创建一个实例 * * */ private static Singleton2 instance = null ; private Singleton2 ( ) { } public static Singleton2 getInstance ( ) { if ( instance == null ) { instance = new

Why can creating a static const std::string cause an exception?

孤街醉人 提交于 2020-01-12 11:51:15
问题 I have string constants, for strings that I use in multiple places in my app: namespace Common{ static const std::string mystring = "IamAwesum"; } When posting a question about something else (What happens to a .h file that is not included in a target during compilation?), another user made the following comment : be aware that your static string are global in this case. So they are could create an exception at anytime and can't be catch. I advise you to use function who return a reference of

static library dependencies

早过忘川 提交于 2020-01-12 09:49:37
问题 I have a static library (.lib file) on Windows platform, I want to know the dependent version of CRT library when the lib is built. I have no source code of the .lib file, any ideas? thanks in advance, George 回答1: Static libraries don't have those kinds of dependencies. When the library is built it is not linked with the run-time in any way, all it knows about are function declarations in the implementation header files, which don't provide any version information. However, assuming the

static if in plain c++?

会有一股神秘感。 提交于 2020-01-12 07:03:54
问题 Problem in short: How could one implement static if functionality, proposed in c++11, in plain c++ ? History and original problem: Recently I came up with a problem like this. I need a class Sender with an interface like class Sender { void sendMessage( ... ); void sendRequest( ... ); void sendFile( ... ); // lots of different send methods, not important actually } In some cases I will need to create a DoubleSender , i.e. an instance of this class, which would call its methods twice, i.e.

设计模式-单例模式

梦想的初衷 提交于 2020-01-12 06:45:32
为什么要是用单例模式? 有一些对象我们只需要一个,比方说:线程池、缓存、对话框、日志对象,打印机的驱动程序的对象。如果这些对象制造出多个实例的话,会导致很多问题产生,例如:程序的行为异常、资源使用过量或者不一致。 确保一个类只有一个实例,并提供一个全局访问点。 全局变量和单件模式? 全局变量基本上是对对象的静态引用。在使用全局变量时会出现急切实例化和延迟实例化。而单件模式确保类只有一个实例并提供全局访问。全局变量可以提供全局访问,但是不能确保只有一个实例。 饿汉式: 初始时就创建出了单例对象,可以增加线程安全,但是造成资源浪费。 class mySingle { static mySingle singleLeton = new mySingle ( ) ; private mySingle ( ) { } public static mySingle getInstance ( ) { return singleLeton ; } } 懒汉式:不安全,在调用获取实例时才进行实例的创建,线程不同调用时可能会出现不同的实例,导致线程不安全。 class mySingle { static mySingle singleLeton ; private mySingle ( ) { } public static mySingle getInstance ( ) { if (

Why is a subclass' static initializer not invoked when a static method declared in its superclass is invoked on the subclass?

拜拜、爱过 提交于 2020-01-12 02:52:08
问题 Given the following classes: public abstract class Super { protected static Object staticVar; protected static void staticMethod() { System.out.println( staticVar ); } } public class Sub extends Super { static { staticVar = new Object(); } // Declaring a method with the same signature here, // thus hiding Super.staticMethod(), avoids staticVar being null /* public static void staticMethod() { Super.staticMethod(); } */ } public class UserClass { public static void main( String[] args ) { new

Django 批量插入数据

纵然是瞬间 提交于 2020-01-12 01:25:04
项目需求:浏览器中访问django后端某一条url(如:127.0.0.1:8080/get_book/),实时朝数据库中生成一千条数据并将生成的数据查询出来,并展示到前端页面 views.py from django.shortcuts import render, HttpResponse, redirect from app01 import models def get_book(request):   # for循环插入1000条数据   for i in range(1000):     models.Book.objects.create(name='第%s本书'%i)   book_queryset = models.Book.objects.all() # 将插入的数据再查询出来   return render(request,'get_book.html',locals()) # 将查询出来的数据传递给html页面 urls.py from django.conf.urls import url from app01 import views urlpatterns = [ url(r'^get_book/',views.get_book) ] models.py from django.db import models class get_book

使用django自带后台管理系统,uwsgi启动css格式消失的问题

回眸只為那壹抹淺笑 提交于 2020-01-12 00:06:36
问题 :CSS加载的样式没有了, 原因 :使用了django自带的admin,在使用 python manage.py runserver启动 的时候,可以加载到admin的文件。 而在使用uwsgi启动的时候,一些网页需要的静态文件uwsgi没有找到,所以出现了比较丑陋的情况。 解决方法: 将admin的文件找出来放在static里面,通过uwsgi进行加载; step1: 先收集到all_static下,之后转移到static下; 在settings.py 里 添加 STATIC_ROOT=“all_static” STATIC_URL = '/static/' STATIC_ROOT = os . path . join ( BASE_DIR , 'all_static' ) ST . path . join ( BASE_DIR , 'static' ) ] MEDIA_ROOT = os . path . join ( BASE_DIR , 'static/media' ) 注意一定要是 STATIC_ROOT 不然收集不到 step2: 终端,在manage.py的同级下执行 python manage.py collectstatic 生成如下文件,admin文件是我们想要的。 step3: 将admin文件移动的static下;ps:这一步不是必要的